Compare Django and Flask
Django is Python web framework that encourages rapid development. It is based model-template-view (MTV) design pattern. It follows a "batteries included" philosophy and ships with many tools that are needed by application developers such as ORM framework, admin panel, directory structure and more.
Flask is a Python web framework for building web applications. It is based on Werkzeug and Jinja 2. It is a minimalist, 'no batteries included' framework. Yet it can be scaled extensively and support complex applications and use cases by adding required functionality as needed. It follows the philosophy that if something needs to be initialized, it should be initialized by the developer.
Let's see how Django and Flask compare on various factors and features and which to choose when.
Type
Python all-inclusive, megaframework for building web application.
Type
Python microframework for building web applications.
Used by 367,000 projects.
Used by 397,000 projects.
Used by
Instagram, Pinterest, Coursera, Udemy.
Used by
Netflix, Zillow, Lyft.
2074 job openings which list Django as a requirement.
1067 job openings which list Flask as a requirement.
Not as fast as compared to bare-bones Flask or other microframeworks, but for many real-world use cases, the difference is negligible.
Because it is minimal and doesn't have a lot of overhead, Flask is very performant. Extensions could impact performance negatively.
Flexibility
Django expects things to be done in a certain way unlike microframeworks (e.g. Flask) which have no opinion on how developers structure things. However, It does this without compromising on flexibility. Django has been used to build a variety of things from content management systems to social networks to scientific computing platforms.
Flexibility
Very flexible and doesn't require users to use any particular project or code layout. (A structured approach is still recommended.)
Ease of Learning
Has a learning curve especially for those who are not familiar with other web frameworks. But there are some great online resources, courses tutorials and YouTube videos.
Ease of Learning
Flask is simple and its core features are not difficult to learn. There are also plenty of online resources available to aid in learning.
RDBMS Support
Django ships with a built-in
ORM framework for developers to start using out of the box.
Verdict ORM is one of the best features of Django, loved by developers.
RDBMS Support
Through Plugins or Extensions
Flask doesn't come with a built-in ORM framework. Developers can use one of many open source libraries or extensions. Such as
Flask-SQLAlchemy,
Flask-Pony, etc.
NoSQL Support
NoSQL databases are not officially supported by Django. There are open source projects like
PynamoDB or
Django MongoDB Engine,
Django non-rel to support NoSQL. Some of these extensions support specific Django versions and don't
interplay well with Django ORM.
Verdict Using NoSQL database with Django is not recommended.
NoSQL Support
NoSQL databases are supported through open source libraries or extensions. To use MongoDB with Flask,
Flask-PyMong is a popular choice. CouchDB, Cassandra, and DynamoDB are also supported via libraries.
Verdict Flask is a great choice if you want to develop for a NoSQL database.
Admin Dashboard
Django ships with a web-based admin site that has a friendly UI. It allows you to quickly perform CRUD operations against your models from your browser to test things out.
Admin Dashboard
Through Plugins or Extensions
No built-in admin panel, but you can use the
Flask-Admin extension. It supports a number of backends like SQLAlchemy, MongoEngine, Peewee etc.
REST Support
While not built-in, REST development is supported via the popular and active
Django REST Framework project. It provides support for API versioning,
Browsable API for interacting with APIs through web browser, authentication (OAuth1 and OAuth2) and serialization support for both ORM and non-ORM sources.
Security
Built-in protection against several common attack vectors like CSRF, XSS, and SQL injection. When vulnerabilities are discovered, the Django team has an excellent
security policy and
fixes are released quickly.
Security
Despite being a minimalist Framework, Flask does an excellent job of addressing common security concerns like CSRF, XSS, JSON security and
more out of the box. 3rd party extensions like
Flask-Security can be used for common security measures. However, it requires that developers evaluate these extensions carefully for security risks and apply timely updates manually when vulnerabilities are discovered.
Templating Library
Flask uses
Jinja2 out of the box.
Web Forms
Ships with built-in
ModelForms which provides complete support for web forms including input validation, CSRF, XSS, and SQL injection.
Web Forms
No built-in support but there is
Flask-WTF extention. For SQLAlchemy support, that is, to create forms based on models, there is
WTForms-Alchemy
Authentication
Built-in
authentication, authorization, account management and support for sessions.
Testing
Built-in support using Python's
unittest framework.
Testing
Built-in support using Python's
unittest framework.
How is performance rating determined?
Performance rating is determined using reputable online benchmarks listed below.
Where is job data coming from?
Job data is collected from Indeed, Google Jobs and Stack Overflow jobs.
How is popularity calculated?
Popularity is calculated using a formula which looks at weighted score on the following publicly available data points:
- Popularity per Google Trends
- Number of GitHub Users
- Number of GitHub Stars
How is this calculated?
Ease of learning is calculated using the following data:
- Number of features and depth of tool.
- Number of online resources: articles, blogs, tutorials and YouTube videos.
- Number of courses
- Freshness of online material
For example, a microframework may not have a lot of online resources but still get a high-rating because it's minamalistic and easy to learn just by following official documentation.
If you found this useful, please help us grow by sharing this article with your followers using the sharing icons. Every share or call out will help. Thank you.
Similar Comparisons
Comments (1)
Abdur-Rahmaan Janhangeer
REST for Flask, Marshmallow seems nice!