Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Right now, I'm writing most of my projects in Tornado.. Not because I need the async, but because I wanted a simple web.py like format that was under active development.

Can someone help me understand where Flask fits into things? It would essentially be a replacement for Tornado? What's the advantage of this over Tornado? Ease of use?

I can understand the simplicity argument; I chose to avoid Django because it was too heavy, so I'd love to hear more about how Flask compares.



Tornado is batteries included. Flask uses Werkzeug and Jinja2 and encourages packaging extensions for localization, form processing, ORM's etc.. Flask, Werkzeug and Jinja2 are all Pocoo projects that have a good community around them and excellent documentation. Technically I would not like to argue the superiority of either, although Flask seems to fit my tastes much better.

Flask's use and deployment of "magic" is pretty spot on. For example by making the request object omnipresent (that is flask.request is always bound and has the right context). That way it is not passed around the MVC stack but just imported and introspected when needed.

Flask is probably the "healthiest" project I've encountered.


Why would it be good to avoid passing around the request object?


Armin explains the request object here (http://flask.pocoo.org/docs/reqcontext/) and here (http://flask.pocoo.org/docs/quickstart/#id4), and the concept of "context locals" in detail here (http://werkzeug.pocoo.org/docs/local/).


Can someone help me understand where Flask fits into things? It would essentially be a replacement for Tornado? What's the advantage of this over Tornado? Ease of use?

Pretty much yes to all of this.

I can understand the simplicity argument; I chose to avoid Django because it was too heavy, so I'd love to hear more about how Flask compares.

Flask "feels" more like CherryPy than Django to me, but yes, it's more lightweight than Django and more modular (doesn't define an ORM, etc).

The thing that keeps me from using Flask for any serious work is Django's admin interface. That thing saves me ridiculous amounts of time.


Couldn't you use inspectdb to introspect your Flask database and use Django's admin that way? You'd have to remember to do it every time you changed your database; but it'd probably get you most of the way there.


>You'd have to remember to do it every time you changed your database;

That's probably why he just finds it easier to use django.


I don't disagree with that sentiment for use during development; but for a long-lived application I don't think it's nearly as big a deal.

I don't know about you, but I've personally found that after a few months of working on an application the models tend to be pretty stable.


For a web framework(non async run of the mill), I would say Flask has an edge. My Flask stack is:

1. SQLAlchemy for ORM.

2. Jinja2 for templates (flask default).

3. Flask for basic web framework functionality.

4. WTForm for forms.

5. Other extensions as needed.

Flask itself is built on werkzeug which is a clean, high-level wrapper over WSGI. Basically Flask is assembling working components into coherent applications. I have done some applications in flask and I can say it's suited for applications of all size.

Tornado, on the other hand, implements its own templating and orm.


Tornado doesn't have any orm, it only has a very thin wrapper around MySQLdb.


Flask is a simple web.py-like framework that is under active development, and I would argue it's one of the cleanest Python Web frameworks (if not the cleanest) out there.

My current project requires real-time stuff so I started to develop it using Tornado and then decided to switch to the Quora model -- use a traditional Web framework for most things, and connect back to Tornado for the real-time stuff.

Quora uses Pylons, but Pylons reached its end-of-life with 1.0, and it's now Pyramid, which is really repoze.bfd and shares no code with Pylons 1.0.

So I swapped out Pylons for Flask and use Sockeit.IO (http://socket.io/) to connect back to Torando for real-time connections.

In addition to just being really-well designed, Flask has an amazing debugger that makes me more productive, and it's easier to write unittests for Flask because you can write them in a traditional way and don't have to contend with Tornado's IOLoop.

When I switched to this model, the development process sped up considerably.

For real-time stuff, you could forgo Tornado all together and instead use gevent to deploy your Flask app (http://flask.pocoo.org/docs/deploying/others/#gevent), like some have done with Django and Pyramid (http://blog.abourget.net/2011/3/17/new-and-hot-part-4-pyrami...), but I haven't tried this yet.


BTW: Charlie Cheever, one of Quora's founders, recently said they would have considered Flask if it had been released by the time they were setting things up (http://www.quora.com/Why-did-Quora-choose-to-develop-in-Pylo...).


You can actually use Flask from within Tornado's WSGI adapter.

http://flask.pocoo.org/docs/deploying/others/

This lets your leverage Tornado's high-performance IO loop while still developing your web application using Flask.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: