DEV Community

Cover image for Comparing Flask and Django
Sophia Iroegbu
Sophia Iroegbu

Posted on

Comparing Flask and Django

Python is one of the most widely used programming languages, thanks to its clean, readable code and adaptability. It is also in high demand due to its wide variety of web frameworks, which can quickly transform your project from a mere concept to an amazing reality. There are numerous frameworks, but only two stand out: Flask and Django.

Now let's compare Flask and Django based on some of the core framework's features:

The Database:

Django has a robust Object Relational Mapping (ORM) framework that supports a variety of relational databases such as SQLite, PostgreSQL, MySQL, and Oracle, as well as managing and generating database migrations.
Flask makes no promises on how data is stored, but there are several libraries and extensions available to assist with this: Flask-SQLAlchemy, Flask-Alembic, Flask-Peewee, and so on.


Django has a powerful admin screen, which is a desktop application with a user interface for handling data based on the templates. Django excels in this field as well. It enables you to easily execute CRUD operations on your templates when building out an application without writing any additional code.
Again, Flask does not come with anything like this by itself, but the Flask-Admin extension has the same functionality.

Views and Routing:

Both frameworks support mapping URLs to views and feature and class-based views, but Django fits a URL pattern, the request object, which contains the HTTP request content.
Flask makes use of Werkzeug to provide URL routing and request/response handling. It requires that the item in Flask be global in order for it to have easy access to it (as long as you import it).
URLs are typically specified alongside the view (via a decorator), but they can be broken out into a centralized position, similar to the Django pattern.


Django has built-in defense against a variety of standard attack vectors such as CSRF, XSS, and SQL injection. This security features help to protect the code from bugs. In addition, the Django development team proactively discloses and promptly patches identified security bugs. Flask, on the other hand, has a much narrower code base, which means there is less surface area to strike. However, when security flaws in your hand-crafted app code emerge, you will need to correct and patch them.


It isn't so much about the right structures as it is about personal preference. Simply enjoy yourself when coding.

Top comments (5)

tyu1996 profile image
Brian Ting • Edited

Both frameworks are designed to have different direction from the beginning.
Flask is way lighter and more flexible that developers can choose whatever plugins they needed just enough for their web apps.
Django is specially for big scale web app so it is all-in-one solution and gives developers power to do many complicated things.

sophyia profile image
Sophia Iroegbu

Very true brian. I prefer django, though.

techmaniacc profile image
Joseph Mania

Am adjango e-commerce hero

danidiaztech profile image
Daniel Diaz

We can say that Django is built for manage the entirely project, and flask is made for create microservices

henriavo profile image
Henri Idrovo

These two are definitely worth comparing! My favorite project that uses flask is: