Live data from Hacker News

Ask HN: Best Python web framework

news.ycombinator.com

41–50 of 110 posts

Re: Ask HN: Best Python web framework

#42

Sadly, Django is still by far the most popular. It's ok, though. You're likely to not hate it intensely. It also has a lot of third party code available, and a fair amount of functionality built-in. Flask is nicer (and lets you seamlessly use SQLAlchemy, which is so much better than Django's crappy ORM), but also tiny. It's basically just a bit of glue between werkzeug, SQLAlchemy and Jinja2. Pyramid has more things…

I don't think it's a sad thing. For most websites and apps, Django is perfectly great and has things like patterns so if you want to genericify some of your code and use it on another site, you can just modularise it in an app. Flask has extensions and blueprints, but I find it far less friendly.

Re: Ask HN: Best Python web framework

#43
post #19

(Full disclosure: I'm a member of Django's core team) There's no single "best" for every application. One-size-fits-none. One of Django's strengths is in the fact that parts of the framework come off easily when they no longer serve your needs. If the ORM is no longer working for you, you can use SQLAlchemy or write raw SQL. Authentication no longer working for you? Write your own or use a 3rd party one. Et cetera. T…

I use both and personally if I'd have to generalize I would say Django for simpler stuff and Flask for complex stuff.

Flask is great if you're going to do a complex app. All the interface will be custom designed (so the Django admin is of no use). You have a database heavy app, SQLAlchemy is more flexible than Django ORM and allows greater SQL expression, Unit of Work etc. Jinja2 is more flexible then Django templates (and faster). Flatland is more flexible than Django forms (supports nested forms for example).

That being said, Django is also great for some large apps and just for example it's great for news sites where new types of content is added each day and the admin interface saves a ton of time. For simple apps it's also brilliant because everything that's in Django works well together and you don't need the extra features of the aforementioned libraries.

So to sum up, both great frameworks and I use both every day :)

Re: Ask HN: Best Python web framework

#44
post #37

Pyramid. http://en.wikipedia.org/wiki/Pyramid_%28web_framework%29 * faster. * better quality (100% statement coverage via unit tests) * supports latest python. * great documentation (including free up to date book). There's also a separate pyramid cookbook. * simplicity. If you just see a pyramid app, you can dive right in fairly easily without learning lots of alien stuff. * sensible defaults, and you can choose to…

As an alternative viewpoint

* It's complicated

* It doesn't really do much for you (have to spend lots of effort/time/learning plumbing in all the 3rd party libs)

* Lacks sensible defaults for many things

* Documentation is rather lacking. Oh, there's tons of it, but it's rather maze-like and hard to use if you don't actually understand the system. High-level overview/cookbook type stuff is severely lacking.

Re: Ask HN: Best Python web framework

#45

I really like bottle.py [1]. I've used it for a couple of different projects; although not fundamentally different from web.py or flask, it seems to just "make sense". [1] http://bottlepy.org/docs/stable/ An example from their website: from bottle import get, post, request @get('/login') # or @route('/login') def login_form(): return ''' ''' @post('/login') # or @route('/login', method='POST') def login_submit(): nam…

PHP guy here, don't know much about other languages, but seeing HTML mixed in with code is usually a bad code smell. Is this type of thing common in Python?

Those micro-frameworks are designed to make a hello-world app very short and to the point. There's one (aspen.io) that uses the ^L character as a section separator to achieve maximum concision: setup, request handling, optional template. No space is wasted on function blocks or explicit registration calls.

Re: Ask HN: Best Python web framework

#46
post #34
post #28

Earlier quoted context omitted.

I would simplify further: Are you building an API? If yes, use Flask. Are you building a website? If yes, use Django. Are you building an API and a website? If yes, use Flask for the API and consume it from a Django site. I wouldn't advocate using Django but ditching the ORM for SQLAlchemy, nor replacing the Auth, as noted (above or below my comment) it gets messy and becomes a lonely road fast. I would advocate movi…

I disagree on one point there... if you're building both an API and a website, there's no reason at all to use both Flask and Django. I can't imagine that the benefits would outweigh the disadvantages of having to deal with two frameworks instead of one. I'd also argue in favour of ditching Django's auth. It's fine if your project has very simple auth requirements, but these days very few interesting projects have si…

> I can't imagine that the benefits would outweigh the disadvantages of having to deal with two frameworks instead of one.

Separation of concerns, loose coupling.

I tended to find (in the few Django projects I worked on), that models were frequently accessed outside the app that created and owned the model. The subsequent dependency diagram would be spaghetti.

We had apps for each significant feature area, and when we wanted to drop a feature it was my desire to just remove an app.

It may well have been our implementation that was the problem (poorly separated concerns across apps), but we made great strides at solving these problems by using APIs to both force the de-coupling and to increase our confidence that our mobile clients (using the API) had the same capabilities available to them as the website (because no Django dev could cheat and make a call without the API existing).

Why Flask and not just Django again? That came down to personal preference over how clean it is to handle headers correctly (Accept headers, CORS and other things were fun), layout of the code and project, simplicity of testing, etc.

Mostly it was just subjective and personal preference, once we saw that the Django projects we had tended not to follow loose coupling, we used APIs as a way to increase our own discipline. Preferring that the architecture helped ensure the way we wanted to work on (and maintain) the code.

Auth we had already externalised (into the edge of the network, implemented within Varnish, similar to Flickr's GodAuth).

Re: Ask HN: Best Python web framework

#47
post #36
post #28

Earlier quoted context omitted.

I would simplify further: Are you building an API? If yes, use Flask. Are you building a website? If yes, use Django. Are you building an API and a website? If yes, use Flask for the API and consume it from a Django site. I wouldn't advocate using Django but ditching the ORM for SQLAlchemy, nor replacing the Auth, as noted (above or below my comment) it gets messy and becomes a lonely road fast. I would advocate movi…

Disagree, Django Rest Framework and TastyPie make REST APIs effortless: write Django models, register them with the REST plugin, hook the plugin to your main URL structure. They're a really good example of how Django enables reuse. Implementation-wise they both hook into the model framework and the form framework, although you can swap out those parts if your data lives elsewhere.

I see what you're saying.

But I disagree that:

Database = Model = Resource

Re: Ask HN: Best Python web framework

#48

I really like bottle.py [1]. I've used it for a couple of different projects; although not fundamentally different from web.py or flask, it seems to just "make sense". [1] http://bottlepy.org/docs/stable/ An example from their website: from bottle import get, post, request @get('/login') # or @route('/login') def login_form(): return ''' ''' @post('/login') # or @route('/login', method='POST') def login_submit(): nam…

PHP guy here, don't know much about other languages, but seeing HTML mixed in with code is usually a bad code smell. Is this type of thing common in Python?

PHP is about mixing it with other stuff (hence the <?php tag). So PHP smells by definition :-)

Re: Ask HN: Best Python web framework

#49
post #46
post #34

Earlier quoted context omitted.

I disagree on one point there... if you're building both an API and a website, there's no reason at all to use both Flask and Django. I can't imagine that the benefits would outweigh the disadvantages of having to deal with two frameworks instead of one. I'd also argue in favour of ditching Django's auth. It's fine if your project has very simple auth requirements, but these days very few interesting projects have si…

> I can't imagine that the benefits would outweigh the disadvantages of having to deal with two frameworks instead of one. Separation of concerns, loose coupling. I tended to find (in the few Django projects I worked on), that models were frequently accessed outside the app that created and owned the model. The subsequent dependency diagram would be spaghetti. We had apps for each significant feature area, and when w…

How do you handle "foreign key references" between modules in your new approach (using APIs to decouple?).

Re: Ask HN: Best Python web framework

#50
post #7

Pylons is now called pyramid. I don't know how much it changed? I prefer pylons above Django. Simply because it feels less like a framework.

> I don't know how much it changed? All of the controllers stuff was replaced with the code formerly known as repoze.bfg

While Pyramid is Pylons' appointed successor, the code is mostly from the repoze project, with changes to make it more familiar to Pylons users: http://docs.pylonsproject.org/en/latest/faq/pyramid.html
Post reply on HN