When to use Flask or Django?

This is an interesting comparison, as both are capable of building a simple to complex applications, of course both have slightly different ideology in achieving things. So, I will just put my two cents to both the frameworks with this post and let you decide.

Let us look at the comparisons:

  • Django has been around much longer, so it has got some projects built as a legacy codebases, Flask is comparatively younger.
  • Django comes with out of the box support for ORM. The ORM in Django is very easy and robust to use, Flask doesnt have inbuilt support for ORM but has external libraries which could be used to make that happen, ex; Flask-SQLAlchemy, a special mention to Flask-Peewee, it has ORM, an admin interface, REST api, and auth/security too.
  • Django has a very cool admin system. You can use it for CRUD related operations of your models or you can just completely customize it according to your needs. This is absent in Flask and has to be integrated through external module such as Flask-Peewee.
  • Django has “batteries” which help a developer get started easily and is extensible along the way too. Flask, being a micro web framework, does not ship with those, but on a long run could be implemented, but again, that will be custom made or by external module support.
  • Django and Flask both has huge community base support and has extensive online presence.
  • Django modules and libraries are larger in number than Flask, but Flask is catching up with Django.
  • Django middleware is a nice feature, it sits between your view and incoming request and outgoing response. Flask does not have this but again you have to develop something custom made or rely on other modules.
  • The most common security concerns of the web is covered in Django, Flask is not there yet on its own. Flask-Peewee and other modules are there which could be used to make this happen. A special mention to ‘Flask-Security’ module here would be good too.
  • Flask is very easy to get started with for Python developers, and for Django you need to do a little bit of learning before you get started. I would say for beginners to web programming, and who wants to get a feel of how web frameworks works, Flask would be a good start.
  • Flask could be used to develop web application which serves and consumes REST api, again using some external module or custom developed module, but Django could be used their too with Django Rest Framework, which is also an external module.
  • Many articles I had a read says that Flask is good for those who want to use NoSQL, but I beg to differ, Django could play good with NoSQL databases too.
  • If you have a specific requirement to have a medium or small sized app, may be to serve files etc, or may be for podcast blog, or REST application, internal application stack, or some microservices application, then you can use Flask, but again, that is up to personal preference. You could do all the things in Flask which you could do on Django and vice-versa. Just that Django would make it easy, and with Flask may be you need to build things or integrate through external modules.

Some of the big webites/services built using Django and Flask are:

  • Django : Dropbox, Quora, Survey Monkey, Bitly, Disqus, Spotify.
  • Flask : InkMonk (backend), some parts of Reddit, Uber uses it with Nginx on http://vault.uber.com, POTUS Obama used it for their campaign in 2012. Twilio uses Flask RESTFul for all their public and private api.