/ Learn Python Programming

Should I learn Flask or Django?

There are multiple popular web frameworks for Python, and two of the most popular are Flask and Django. Other web frameworks are Tornado, aiohttp, and Sanic, for example.

A popular question is: "Should I learn Flask or Django?".

The answer is: it depends.

Flask

Flask does a lot less for you than Django does, and in exchange it has an easier learning curve.

In simplest terms, Flask allows you to map routes (web addresses) to Python functions. It provides a few more pieces of functionality, such as sessions and template rendering.

Since it is so lightweight, Flask can be better to get started quickly and understand fully what your application is doing. That's because you'll be writing everything your app does, instead of allowing Django to do some things for you.

A lot of functionality can be added to Flask via extensions. There are many extensions to add things like ORM support, rate limiting, form creation, and many more.

Django

Django does much more for you out of the box, and as such it is more complicated. It requires a bit more setting up, and it is generally quite opinionated in the way that you should do things when working with Django.

That can be a good thing, because it means it can be clearer how to implement certain things, whereas Flask gives you a bit more freedom and it can potentially get messier.

Because Django gives you so much out of the box, it can be much faster to get a web app up and running when it's a "standard" app. It makes it easy to get an administration panel, user registration, and database interactions up and running with few commands.

In my personal experience though, once that's working Django becomes a bit more cumbersome because you didn't write the code to do all that yourself. It can be a bit confusing, particularly for the beginner.

When to use each

If you have a bit of Python experience, you know exactly what you want, and it's a fairly standard web application that involves displaying some content, storing some stuff in a database, having users register, and having administrators be able to control what's on the website: use Django.

If you are a Python beginner: use Flask.

If you want to learn more about the inner workings of your application and want the freedom and flexibility to program it in whatever way you see fit: use Flask.

If you want a lightweight application such as a REST API or an Internet of Things application: use Flask.

Like what you see?

Join our e-mail list to receive new content as it's posted—once or twice a month!