Flask vs Django (2023)

Flask and Django are the two most popular Python-based web frameworks. Both are mature, open-source, and have many happy users. A natural question therefore is: which one to use?

In this article I will cover the relative pros and cons of each framework, provide real code examples, and links to further resources for learning each.

Micro vs "Batteries-Included" Framework

The biggest difference between Django and Flask is their overall approach. Bluntly stated, Flask is simpler but does less while Django has far greater functionality but at the cost of more complexity.

Flask is a simple, lightweight, microframework meaning it provides only basic functionality such as URL routing, templates, cookies, a debugger, and a development server. This makes it arguably simpler to start with and at only ~29,000 lines of code, it's possible--and recommended--to read through all of the source code to figure out what's happening behind the scenes.

When developing a Flask application, the developer is in complete control. Its lightweight nature means that it is easy to add a basic website or a dedicated API endpoint to an existing project. This makes Flask a great learning tool if you're new to web development and also a popular way to add small amounts of web functionality to a large existing codebase that might not be written in Python. The downsides are that the developer is solely responsibility for building out common website functionality such as connecting to a database, handling forms, security, authentication, and so on. Generally these are added using third-party packages which adds another level of risk since they are not guaranteed to be updated and vetted to the same standards as Flask itself. On professional sites, there is also far less consistency to the organization and structure of Flask projects. As a result, Flask is often quite popular at the two extremes of Python web developers: those who are brand new or who are experts and have very particular requirements that require complete flexibility.

Django, by contrast, is a full featured "batteries-included" framework. It has roughly 10x as many lines of code as Flask, ~290,000, but also comes with almost every feature a website will need built-in including database connections, fantastic security, forms, a powerful user admin, and a robust ecosystem of 3rd party packages. This makes it arguably more secure, it leads to far greater consistency among production codebases, and if you know what you're doing Django is much faster to use since you can be up and running with far less code the developer has to write themself than with Flask. The downside of Django's power is that it has a steeper learning curve than Flask. The larger codebase takes much longer to master. If you're brand new to web development, many elements in Django will appear like "magic" at first.


If you're looking for a job as a Python web developer, Django is the better choice. There are almost twice as many listings for Django developers as for Flask on major job boards such as Indeed.com.

However, this disparity is likely due to the fact that Django is a much more specific choice than Flask. A startup or company can run almost all of their services just on Django whereas Flask is often used alongside other technologies given its lightweight footprint.

The most employable approach is to truly master Python first and then add web development knowledge with either Django or Flask (ideally both!) on top.


Django has the larger, more organized community of the two. There are over 1,800 committers to the Django codebase vs around 550 for Flask. On StackOverflow there are ~212,500 Django questions compared to ~31,500 Flask questions.

Django also has annual conferences in both the United States, Europe, and Australia. Flask does not have a similar level of conferences although there are active discussions for both frameworks at PyCon events.

Hello, World comparison

Flask famously features a "Hello, World" example right on its homepage. Here's how to configure it. Navigate to a new directory on your computer, such as a flask directory on your Desktop. Then create a virtual environment, activate it, and install Flask.

# Windows
> cd onedrive\desktop\code
> mkdir flask
> cd flask
> python -m venv .venv
> .venv\Scripts\Activate.ps1
(.venv) > python -m pip install flask

# macOS
% cd ~/desktop/code
% mkdir flask
% cd flask
% python3 -m venv .venv
% source .venv/bin/activate
(.venv) % python3 -m pip install flask

In your text editor create a new file, hello_flask.py, and populate it as follows:

# hello_flask.py
from flask import Flask, escape, request

app = Flask(__name__)

def hello():
    name = request.args.get("name", "World")
    return f"Hello, {escape(name)}!"

Then start the Flask server from the command line:

(.venv) > env FLASK_APP=hello_flask.py flask run
* Serving Flask app "hello_flask.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on (Press CTRL+C to quit)

Navigate to and there is a nice "Hello, World!" message.

Flask welcome page

What about Django? There is no equivalent example on the Django website however we can, in fact, accomplish a similar feat with only a few more lines of code. Navigate to another directory, perhaps called django on your Desktop. Then install Django:

# Windows
> cd onedrive\desktop\code
> mkdir django
> cd django
> python -m venv .venv
> .venv\Scripts\Activate.ps1
(.venv) > python -m pip install django

# macOS
% cd ~/desktop/code
% mkdir django
% cd django
% python3 -m venv .venv
% source .venv/bin/activate
(.venv) % python3 -m pip install django

In your text editor create a hello_django.py file with the following code:

# hello_django.py
from django.conf import settings
from django.core.handlers.wsgi import WSGIHandler
from django.core.management import execute_from_command_line
from django.http import HttpResponse
from django.urls import path


def hello_world(request):
    return HttpResponse("Hello, Django!")

urlpatterns = [path("", hello_world)]

application = WSGIHandler()

if __name__ == "__main__":

And start Django's built-in web server with the following command:

(.venv) > python hello_django.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
March 17, 2022 - 13:48:54
Django version 4.0, using settings None
Starting development server at
Quit the server with CONTROL-C.

Navigate to Django's standard port of 8000,, to see the "Hello, Django!" message.

Flask welcome page

So Django is a bit longer, largely due to the fact we explicitly import functionality more granularly than in Flask. However it's still possible to do a single "Hello, World" from one file and if we explored further, Django has given us much more functionality that is readily available. With Flask, to move beyond the absolute basics installing and configuring additional packages is required.

But the important point is that while "Hello, World" might be a meaningful comparison for a programming language, it is largely meaningless when comparing web frameworks. A real-world Flask application is not contained in a single file, nor is a Django application. So using either benchmark is quite limited in its usefulness.

Killer Features

Flask: - Lightweight codebase and no batteries - If you need a non-relational database - Add a simple website or simple API endpoint

Django: - Batteries-included - Robust documentation - Vibrant community - Powerful built-in admin - Async capabilities - Security is a priority


So which web framework to choose?

Ultimately a Flask developer strongly prefers the granular level of control it provides, while a Django developer enjoys relying on a large community that with 15+ years of experience has made and frees the developer to focus on what makes a website different, not recreating the wheel.

A Django proponent would say that a Flask developer eventually rebuilds Django itself, poorly and slowly. A Flask advocate would counter that Django is far too heavy, slower for prototypes, and harder to customize as needed at scale.

My personal advice is that most of the time Django is the better choice. Combined with Django REST Framework it can quickly build powerful APIs, while Flask requires more work and more chances to make a mistake. The best approach is to build a few basic CRUD apps with both and decide for yourself which fits your style better.

Join My Newsletter

Subscribe to get the latest tutorials/writings by email.

    No spam. Unsubscribe at any time.