When I teach my coding seminars to undergrads I like to start with a game. First, I ask them to explain a concept (like “web frameworks”). The first person who gets it right earns a small reward. As you would expect, after I give the go sign, dozens of faces sink on their phones, tablets, and laptops googling for the answer. We usually get a winner after a couple of minutes.
Then, I ask my students to put all their devices in airplane mode and go for a second round with a different concept. Obviously, without quick access to the internet, they are forced to go outside and search for internet access. On average, it takes them about 10 to 15 minutes to get an answer.
Finally, we go for a third round, another concept, but this time without using the internet. Of course, that means researching at the library, which takes 30 minutes or more.
After the rewards are handed out, we talk a little about the experiment. Most students think that I’m trying to show them that things were a lot harder when internet access was restricted or non-existent, and yes, there is truth in that, but the point I try to make is about time.
The way we measure time hasn’t changed for a few hundred years, but the way we experience time has. It seems like every day the world moves a little faster, and seconds are more valuable than they have ever been. We work faster, we consume faster, we move faster. Like an expert chef, we surgically skin off wasteful and time-consuming activities so we can have a quality-filled, more productive time.
Let’s stick with that metaphor for a minute. If we are chefs, and our dish is a web application, then a web framework is the skinning knife. By automating the more tedious and time-consuming activities in web development, we reduce the overhead, make better dishes, and deliver them faster to the table.
For perfectionists such as myself, relying on the standardized libraries and templates of a web framework may feel wrong. There is always this little voice in the back of your head telling you that you are cheating, or that you could do a better job if you make everything from the ground up.
And there is a ring of truth to that but, on the flip side, a custom build requires time and resources that you may not have. So, if you chose to go with a web framework, you need reliable technology that you can trust, one that is customizable enough so that you can add your personal touch without sacrificing the benefits of automated processes.
For me, when I have to develop database-driven websites, that web framework is Django
What is Django?
Django is an open-sourced web framework fully developed in Python by Adrian Holovaty and Simon Willison, and named after the legendary jazz guitarist Django Reinhardt. The framework was developed organically in 2003 as the authors made the jump from PHP to Python.
After tweaking the framework for a couple of years, the company World Online decided to release the framework under a 3-clause BSD license back in 2005. Then in 2008, the non-profit organization Django Software Foundation (DSF) was created to maintain Django and promote its use. This makes Django 15 years old as of the writing of this article.
Quite a venerable web framework by any standard, thanks to the DSF and a massive and active community, the framework keeps getting regular updates.
Why Use Django?
Because it’s made in Python!. All joking aside, Python isn’t just the most popular language on the market right now, it’s also very easy to learn, read, and maintain, properties that Django has inherited in one form or another.
We can see this at work in two of the core principles of Django: reusability of components and the “don’t repeat yourself” philosophy. Django promotes using as little code as possible and reusing assets to minimize the time between design and deployment.
Don’t like how Django does something? In most cases, you can customize it with Python. For example, if you are not happy with the admin interface, you can override it with a few lines of code.
Of course, the same could be said for other Python-based frameworks like Flask, but there are more reasons why Django is so good:
- Friendly community and broad libraries: Since Django has a reputation of being the stepping stone for new web developers, the community around it has the reputation of being one of the friendliest ones out there. As such, Django users have access to a plethora of packages for their work, including the Django REST framework (for building APIs) and Django CMS for managing website content.
- Out-of-the-box solutions: Django comes with many easy to set-up solutions such as an object-relational-mapper so that you can describe the database layout in Python or a fully equipped administrative interface that provides a model-centric interface that is very easy to use.
- Strong security: Django’s security tools let developers protect their projects from cyberattacks. Such tools include cross-site scripting, cross-site request for forgery, and SQL injection. Also, using a web-framework is another layer of protection as you are relying on code that has been validated by a community, avoiding possible security risks created by Python coding.
- It’s mature: With more than a decade under its belt, Django has gone through multiple revisions, and it’s been used for all kinds of web apps such as online stores, news websites, and even social media. Whatever your project, odds are there is a tutorial, documentation, or a Stack Overflow thread you can check for inspiration.
So, What’s the Catch?
No web framework is perfect, and even Django has its fair shares of issues that a perfectionist should understand before using it:
- Slow performance for small apps: Django is a massive and powerful framework that was originally envisioned to develop complex web projects. As such, all the features that come with it can negatively impact very small apps that would run at a brisk pace with less intensive frameworks like Flask
- No multiple-requests: More modern frameworks improve the performance of a web app by letting each process handle multiple requests. Unfortunately, Django was created in a time before that was the norm. As such, a developer will have to hack ways for individual processes to handle multiple requests (or brute force a solution)
- It’s tightly coupled: While Django sells itself as a low-coupling solution, that was true over a decade ago, but not anymore. Other frameworks allow for more loosely-coupled components in comparison.
What’s the Final Verdict?
For smaller projects, you might be better off with Flask as an alternative. Most Python developers see no problem in knowing both frameworks and picking the best one depending on the size and scope of the project.
For developers who want a high-quality product and are on a tight deadline, Django is a powerful framework that is scalable, customizable, and relies on one of the most versatile languages on the market.