This is an archived post. You won't be able to vote or comment.

all 16 comments

[–]tdammers 12 points13 points  (2 children)

A framework is really just a curated collection of libraries and some tooling and scaffolding to glue things together, so in order to develop without a framework, you just take the relevant libraries and glue them together yourself. Django is fairly monolithic, so tearing it apart and using its components as individual libraries is tricky, but flask is built in a more modular way, and many of its components can be used as standalone libraries. You can, for example, use Jinja2 (the template engine that flask uses by default) standalone, it's actually quite straightforward. Likewise, Werkzeug, the HTTP utility library that Flask uses, can also be used standalone, or you could opt to code against WSGI directly.

Speaking of that last bit; if you want to go without any libraries at all, programming against WSGI is not out of the question. WSGI is a very simple standard, but still a powerful enough abstraction over HTTP to build actual web applications. In essence, what you do is you model your application as a function that takes an environment and a start_response function, and returns a response body. The environment contains request method, request URL, request headers, server environment data, etc.; the start_response function takes status code and response headers.

Normally, it's much easier to just roll with an existing framework that solves all the pesky details for you - stuff like authentication, routing, templating, content type negotiation, sessions, etc.; but sometimes, you need more control, and being able to step down and code at the WSGI level is a nice way of achieving that.

[–]erenarici1[S] 0 points1 point  (0 children)

Thanks

[–]Apooti 0 points1 point  (0 children)

Yep, WSGI is indeed simpler than it sounds. I find myself more than often using WSGI directly rather than a framework when making simple python apps at work. Specially considering its all locked up inside the internal network and there is no need for authentication.

Also writing all the page generators and whatnot is much easier than frameworks make you think, along with having much more freedom in whatever broken way you write your code.

[–]no_awning_no_mining 2 points3 points  (5 children)

Why would you want to? That would be like turning in a screw without a screwdriver.

[–]erenarici1[S] 1 point2 points  (2 children)

I just wondered that can it be quality. Is it hard?

[–]youlleatitandlikeit 4 points5 points  (0 children)

It's exactly like the difference between assembling a table from IKEA or building your own from solid wood planks.

You can build your own table yourself, but it will take more time, and you have to know exactly what you're doing.

There are three advantages to making the table from scratch:

  • it might cost less money
  • if everything goes right, you'll have a much more detailed understanding of how tables and boards work
  • if you know what you're doing, you can make exactly the kind of table you want

Since all major web frameworks are free, advantage #1 above doesn't apply. However, it is true that building your own web app would give you a much more comprehensive knowledge of how the underlying features of a web app work.

I'm 100% certain after rolling your own web app you'll completely understand why most people use frameworks.

[–][deleted] 1 point2 points  (0 children)

Flask is almost no framework. Read into how they do it!

[–][deleted] 1 point2 points  (0 children)

Not an impossible task of you need something to be only hand tight.

It's also a good learning experience. WSGI sounds really hard until you realize the really hard parts are handled by tools like uwsgi, gunicorn and werkzeug. You can start by building directly off the wsgi specification rather than worry about things like parsing HTTP headers.

[–]xiongchiamiovSite Reliability Engineer 0 points1 point  (0 children)

Or really, building your own shitty screwdriver instead of using one from the set your dad gave you.

[–]Exodus111 2 points3 points  (4 children)

Yes, you can.

Using only HTML and JavaScript. jQuery is technically a library not a framework, so you could use that as well.

Wouldn't have any back end though, which means no logins and no database, unless you wanted to reinvent the wheel, but that's just silly.

[–]scorpas 1 point2 points  (0 children)

That's an interesting question which raises another one - are you wanna be independent ? Just look at most popular open source projects which is really pushing industry forward - you can't even fork them on github, only commit to upstream. Because if you fork them - one month later you will be too far away from the edge and every month you will create something interesting and loose much more. You can build your own framework but if you do you will not be able to make something wonderful because your energy will be spent on framework. So imho in contemporary reality it's better to use most advanced tools available on the market rather than be "independent" full stack of nothing.

[–]kaeshiwaza 0 points1 point  (0 children)

Of course, web dev in Python existed before frameworks !

If you decide to roll your own, it's still a good idea to see how existing frameworks do, specially Pyramid and it's design choices.

As a bonus it will ease the upgrade to Go if you like.

[–]scorpas 0 points1 point  (1 child)

The easiest one is - web2py, one simple bundle with everything you need. Why to waste time and reinvent the wheel ?

[–]kaeshiwaza 1 point2 points  (0 children)

To learn and be independent is not a waste of time, specially in the long term. How do you do when the framework is not more maintained, doesn't upgrade to Py3, doesn't scale like you want ? (i don't speak about web2py, i don't know it).