Flask vs. Django: Choose Your Python Web Framework
Flask or Django?
According to the 2018 Python Developers Survey, Flask and Django are, by far, the most popular web frameworks for Python developers. You’ll hardly go wrong with either framework if you’re deciding which one to use for a new web application.
While it’s up to you to figure out which one works best for what you’re trying to accomplish, there’s a few major differences you should be aware of when making the decision. Regardless of which framework you end up using, both are very well documented and widely used, so they have ample active and supportive communities.
So, without further ado, let’s take a look at what each framework offers and highlight some of their differences and similarities.
TL;DR Flask vs Django Differences
Flask and Django are mature, extensible web frameworks that, at their core, offer similar functionality in handling requests and serving up documents, but differ in their scope of responsibility.
Most of the differences between the 2 frameworks stem from this different approach although some also stem from some different core design decisions.
Here is a short list of key differences that might impact your decision:
- The Request Object – Flask uses thread-locals while Django passes the request around where it’s needed.
- Forms – Django comes with them built-in and they integrate with the ORM and the admin site. Flask has no default support for forms, but you can use WTForms to fill the gap.
- The Database – Django comes with the Django ORM and a migration system that wants to manage your database. Flask makes no assumptions about a database, but there are tools out there, like SQLAlchemy that provide similar functionality (perhaps more).
- Authentication & Permissions – Django comes with an authentication app that gives a default implementation for user management and permissions. Flask provides secure cookies as a tool for your own implementation.
- Admin Site – Django comes with a fully integrated admin interface for managing application data. Flask doesn’t come with anything like it, but Flask-Admin is a popular extension that can be used to create a similar admin tool.
What is Django?
Django’s website states that “Django makes it easier to build better Web apps more quickly and with less code,” and calls Django “the web framework for perfectionists with deadlines”. Indeed, Django is a mature framework that (by default) makes many decisions on its own so that the user has that cookie-cutter utility needed in a typical web application.
If you’re happy with most of those decisions and the defaults Django provides, you can have a relatively complex web application running in quite a short time.
Some companies that use Django:
- Udemy
- Coursera
- Zapier
What is Flask?
The Flask website describes Flask as “a microframework for Python based on Werkzeug, Jinja 2 and good intentions” and sports the slogan “web development, one drop at a time.” Once again, this gives you a good sense of the space Flask tries to fill in the overcrowded world of Python web frameworks.
Specifically, Flask aims to serve as a minimal framework that handles a few things well, but then leaves more of the decisions on how you want to build your web application up to you – either through custom implementations or any number of 3rd party extensions.
Companies that use Flask:
- Netflix
- Lyft
- Zillow
- MailGun
How do these different approaches pan out?
To better understand the similarities and differences between Flask and Django, let’s take a look at what they offer through the scope of some high-level features you might find in typical web applications.
The development environment
Development Server
Both Django and Flask come packaged with development servers that make it easy and convenient to get started on building your web application quickly. They come with features that you’d expect from a mature web framework, such as the ability to handle requests, serve static files (for development), and detect when your code changes in order to auto-restart and make your changes available.
Back to Top