Why Django Remains My Favorite Python Framework

📅 September 6, 2024⏱️ 3 min✍️ Vincent Cantin Bellemare

In this article, I share my experience with Django and why, after more than 10 years, this framework remains my favorite for web development in Python.

Why Django Remains My Favorite Python Framework

My Love for Python

My love for Python didn't start yesterday. Before, I had worked with PHP for about 4 years. When I discovered Python's syntax, without curly braces {} and without $, it made me smile. I thought: "There's nothing left, just the logic that matters". It was simple, clean, and perfectly matched my programming style, where I've always emphasized good indentation. With Python, indentation is crucial, and I immediately embraced this approach.

Getting Started with Django

My journey with Django goes back to version 1.3. At that time, migrations weren't integrated into the framework. You had to use an external package, South, to manage migrations. Despite this youth, I fell in love with Django. It was clear: everything had been designed to make developers' work easier, with an administrative console directly included. At the time, neither Laravel nor Symfony had an integrated "admin" solution. So you had to code an entire administrative backend for clients, which significantly increased the workload. For me, it was a revelation, and today, 10 years later, my enthusiasm for Django hasn't waned.

Why Django Remains the Best

Django has evolved a lot over the years, but its essence has remained the same. It still offers a powerful ORM, an excellent templating engine, and above all, SQL migrations management that facilitates project evolution. Is it a "low-level" framework? I would say it's just at the right level. Let's compare it with frameworks like Flask and FastAPI. These two are micro-frameworks: they require adding each building block as needed. It's a bit like another one of my passions: music.

An Analogy with Music

I'm a guitarist, and I see similarities between frameworks and guitar pedals. Some musicians like to accumulate pedals, connect them in all directions, change amps, etc. Others, like me, prefer an integrated pedalboard that offers all the functionalities in one package. Certainly, there are limitations in terms of modularity, but simplicity and efficiency are there. For me, Django is my integrated pedalboard. It does everything I need, without having to spend hours assembling pieces.

Security with Django

In terms of security, Django also performs very well. Just update the framework to be sure everything is up to date, in one go. With Flask, on the other hand, you have to juggle multiple plugins: one for templating, one for the ORM (SQLAlchemy), and even another plugin to manage migrations. It's complex and, in my opinion, inefficient.

Flask and FastAPI: The Alternatives

I've explored other Python frameworks, but Django remains the one that convinces me the most. Flask may have its place in specific projects, but only if you don't need an ORM or if you're not working with a relational database. In that case, a static website or a proxy is conceivable.

Async with FastAPI

As for FastAPI, it has the advantage of being asynchronous. I appreciate this feature, and it's true that Django took time to introduce async into its architecture. However, even though Django is not yet completely asynchronous because of its ORM, this doesn't justify a switch to FastAPI for me. FastAPI is excellent for REST APIs, but if you need GraphQL, you'll have to use Graphene anyway, which can also be integrated into Django.

Conclusion

In conclusion, Flask can be useful for very specific projects where a relational backend is not necessary. FastAPI is a good option for REST APIs, but if you have a relational database, I would lean towards Django REST Framework. Ultimately, Django remains my preferred choice because it allows me to move forward quickly and efficiently, while ensuring the security and modularity necessary for my projects.

Share this article