Beginners should use Django, not Flask
Except you, because you are special
Django, not Flask, is the better choice for beginners' first serious web development projects.
While Flask's simplicity and clear API make it great for learning and suitable for experienced developers, it can mislead beginners about the complexities of web development. Django, with its opinionated nature and sensible defaults, offers a structured approach that helps novices avoid common pitfalls. Its comprehensive, integrated ecosystem is more conducive to growth and productivity for those new to the field.
I get it.
Flask has this simple API which makes the "hello world" so clear, so attractive. Then you add a few methods and bam, you get a site. All endpoints fit in one file. You wanna add templates? That's just one more directory. Static files? Same.
Then you try Django, and you have to start with a bunch of commands, mess up with settings, URLS are in a separate file, views have to return a response object, JSON responses are verbose... Plus so many directories and files, what a mess!
That is not a superior first experience.
This makes Flask a great tool for learning about Web development and a superb teaching tool.
And professionally, I still have Flask powered apps running right now from clients' projects I built for them many years ago. No maintenance, just happily serving requests.
Flask works. It delivers.
Yet I say, if you are a beginner, you should not create your first serious project with it.
It's fine for learning, and it's fine once you are an experience web dev.
But in this gray area - that can actually be several years in your career ! - between the first step and the seniority, you should put Django in production.
The devil you don't know
Flask gives you this illusion of simplicity, because it has a good API (except for the global objets like
g which I dislike very much). So it feels you have an easy solution to a simple problem.
But web development is not simple. It is filled with little traps, you have to make a ton of decisions right to create a project that is going to be:
have a reasonable amount of bugs;
is not a security Swiss cheese.
Unfortunately, when you start web dev, you don't know that.
Because you don't know what you don't know.
Which is a lot.
However flask assumes you know. It has a small feature sets, and is not very opinionated. To use it correctly, you have to know what you are doing.
Django on the other hand, is fit with decent defaults. You can't say they are the "best practices", as we all know there is no silver bullet, but it's mostly quite nice. It will tell you to setup CSRF protection, it will forbid click jacking, it will force you to serve static file with a proxy in prod, it will generate a new secret key automatically, it will store session data server side...
Not just that, but Django has an opinion. Like all opinions, it is debatable, but when you start web dev, your opinion likely sucks, and you should adopt Django's. Then once you know what it entails, you can divert from it or change course completely. But at least you start from some practical structure that has been shown to work at scale, instead of a blank page.
Flask will leave you to do whatever. Project layout? You do you. Settings structure? Have at it! How to ship advanced features? You decide!
It's not a good thing when you start. You will make more mistakes and more costly ones. Your project, and whoever is paying the cost for it, will suffer from that. You will at the very least pay it with more stress.
Very few people can actually start anything without some canvas to guide them, and produce something good. They exist, but if you are one of them, you will stop reading the article and I can focus on the people that need it. Which is most people.
Out of the box experience
Django has another wonderful property: it comes batteries included.
Are they the best batteries? There is nothing as such.
Are they productive and battle-tested ones? Certainly.
Data persistence and migration, caching, translation, authentication, internationalization... It got you covered by providing out of the box quantity of tools that solve non trivial problems.
Flask, is different, it's minimalist. You are supposed to either code those things yourself, or use a third party library.
And here lies a huge problem: you are a beginner, you have absolutely no idea which one to use, and how to integrate all that together. And you certainly don't know what it implies from a maintenance and security perspective.
If Flask “hello world” looks so enticing, the Patterns for Flask is the equal opposite, and tell you the real story of what it means to use Flask for a real-life project.
To put Flask in prod, once again, you need to know what you are doing.
And don't get fooled by the recommended modules in the doc. They are not a one-click solution to your problem, they are the beginning of the integration work.
Django seems bigger at first glance, but in fact, starting with it is much less work.
Ecosystem and productivity
My experience with Flask is that the ecosystem is very hit or miss. There are some excellent extensions, but a lot are not nearly at the level of what Django provides without installing anything.
First, integration is subpar, and it will require you to get your hand dirty. It's very much acceptable when you want control, but you, my dear beginner, likely don't. What you need is something that tell you what's possible, then give you a good starting point.
Second, stability is an afterthought. Not only you will hit more bugs with Flask related modules (rarely Flask itself, which is rock solid), but you will get compat issues when upgrading quite often. I still have painful memories of chasing down a flask-admin bug during a deadline with my client sweating next to me.
Third, once again, the ecosystem assumes you know a lot. SQLAlchemy is surely superior db layer than Django ORM. It's also way, way harder to setup, and use right.
What's more, the productivity of it all just cannot be compared. Django ORM is quirky, but it's damn ergonomics for 95% of your CRUD tasks, and fantastically integrated. When you are already twice as slow as you should be because you lack experience, you better not be wasting time fighting with your tools.
This trickle downs to the entire ecosystem, as Django so-called "pluggable apps" are more numerous, often of superior quality and so much better integrated than their Flask counterpart. Trading control for that is advantageous in your position.
Yes, I know
I'm just a guy on the internet that tells you to not use a shiny toy, I don't have a lot of chances to be heard. I'm not fooling myself.
Just understand that I've been programming in Python since 2.4, but more importantly, training people in Python for half of this time. Alternating between shipping code and teaching people gave me a good overview of what works.
Both Django and Flask do.
But the newcomers I met that put Flask in prod for their first projects get scars from it.
Don't get me wrong, you will get scars from your first projects anyway.
You just don't have to get additional ones.
Same opinion on FastAPI, BTW.
If you don’t know what RSS stands for, we also send new articles by email