Is Django still relevant in 2020?
Django has turned fifteen! Many of us who have been working in it for years, can barely believe its age. The Python-based web framework was first released in July 2005, and the world of tech has certainly evolved dramatically since it was born. But is Django now in the grumpy teenage years, or entering its golden age? And perhaps the main question is - is Django still relevant in 2020 and is it the right choice for your digital product? In this blog post we’ll talk you through all the pros and cons and delve deeper into Django web application tools.
What was life like when Django was born?
An interesting fact for you - Django was named after Jazz guitarist Django Reinhardt. Back in 2005 when the language was born, server-side rendered html with some jquery was the way to go, and Django was a pleasure to use in contrast to prevalent PHP. The ORM was nicely integrated with Django Forms, validation and the template engine, which made development rapid.
The Django Foundation: Three years after the language’s official launch, the Django Software Foundation was founded to promote, support, and advance the framework. Since its inception, the foundation has provided ongoing support through sponsoring sprints, meetups, and gatherings, and promoting Django throughout the developer community, as well as protecting its intellectual property and long-term viability, and generally advancing its progress and innovation.
Enter the Django REST Framework
Throughout the early 2000s, single page web applications were becoming more prevalent, along with rest APIs served from the backend to both websites and mobiles. Here, the Django REST Framework was a solution. This is an open source, flexible and fully-featured library with modular and customizable architecture. It brought with it a number of benefits including:
- Ease of use, flexibility, quality, and test coverage of source code.
- A powerful engine for serialization with both ORM and non-ORM data sources.
- Generic classes for CRUD operations.
- Clean, simple, views for Resources, using Django's new class based views.
Adapting to a more asynchronous world
Over the past decade, the world of tech has become increasingly asynchronous. Users now expect instant notifications and status updates, companies want to process huge volumes of data from users actions or other events. And this is done best with asynchronous processing: splitting the system into dedicated (micro)services that use messaging brokers, and communicate with the user over channels such as websockets. And this is where Django might be slightly lacking, but frankly it was never meant to work in this way and solve these kinds of problems.
For some simpler architectures Celery could be used - it integrates nicely with django and can handle some simple workflows. And django-channels could be used for websockets, instant messaging and alike. They will probably be sufficient for many needs, but as the system grows more complex, it’s time to look for something better.
The major pros and cons of Django in 2020
As with any technology, there are many benefits, but also a certain number of shortcomings (often depending on your context and project). We outline the main ones below.
Why use the Django framework?
- Easy to learn and understand: Django uses the Python language, which is one of the simplest programming languages for beginners. For this reason, developers can create applications in Django using clean and maintainable code, taking advantage of Python’s syntax rules.
- Core components do the job: Django used to be called the “framework for professionals with deadlines” and not without reason. From middleware, through ORM to serializers and viewsets (ok, these come from DRF, but still), all these components work together to speed up developments and simplify the code of the app.
- A large and active community and it’s broad libraries: Many developers say that Django’s community is one of the best things about it - because those within it are always actively working on making it more beginner-friendly and stabilizing it while adding new features. Django allows developers to use its vast libraries when building any project. These include the above-described Django REST framework, which is responsible for building application programming interfaces (APIs) and Django CMS, which is designed to manage website content.
- An out of the box admin interface: Django offers an administrative interface right out of the box that is professional and versatile. It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site.
- Reliable and Functional Security Features: Django’s built-in security features enable developers to protect their digital products from a wide range of targeted security attacks, including cross-site scripting, SQL injection, and cross-site request for forgery. At the same time, the web frameworks upgrade the security of web applications by preventing common security mistakes related to Python coding.
Things to be mindful of with Django:
Like with many frameworks, Django has its shortcomings. Below, we outline just a few.
- It’s not always great for smaller web apps: As mentioned above, the powerful features offered by Django make it easier for software engineers to develop large and complex web apps in an efficient manner. But, when it comes to smallers apps, these additional features can be unfavourable in execution. Henceforth, Python developers need to explore approaches to enhance the execution of small web applications while using Django. It can result in unnecessary loading times for small websites which could otherwise run on very little bandwidth.
- Its components are somewhat tightly bound: We already wrote about the fact that Django has certain set components that work closely together, which can be beneficial, as they improve efficiency of development. But at the same time, the so-called “Django Way” can be fairly restrictive, so much so that if you don’t follow the rules, you may actually be unable to implement some things the way you need without resorting to hacky solutions. For this reason certain developers prefer Flask to Django. If you would like to read an in-depth comparison of the two frameworks, you can do so here.
- It can’t serve multiple requests at the same time: Unlike many modern web frameworks, Django doesn’t enable individual processes to deal with several requests at the same time. You need to create a sufficiently high number of workers running django to serve the traffic, which is less efficient and more resource-hungry than solutions like node.js or FastAPI, that run an event loop and switch between requests when they have to wait for anything, leading to more efficient resource usage.
- Relies on its own ORM System: The ORM system given by Django makes it easier for developers to work with various databases and perform common database operations. It also speeds up development because other components are integrated with this ORM and you can easily create CRUD endpoints based on the ORM models. However, the ORM system used by the web framework does not have robust features given by other widely used ORM systems. Also, it does not empower developers to take advantage of the robust Python SQL toolbox fully, so if you would like to use different ORM, like SQLAlchemy because your other services use it - you are out of lack, if you replace Django ORM with different ones you will lose many of the goodies.
- Scalability: Django will scale if need be, of course. Nowadays you just put the app in a docker container and spin up as many of those as you need to serve your traffic. The issue with Django is that the containers tend to be quite big, and starting Django takes time before it starts accepting connections (running inside AWS lambda may not be a good idea). It may also be a bit more resource hungry than alternatives. In many cases this will not be an issue, but it may pose some problems once in a while.
Django or Flask?
If you’re asking yourself: What are the benefits of Django vs Flask, you might also be interested in our blog post on this subject: Flask Vs Django - which Python Framework is best for your app?
The main projects that Django is suited to
Django, which provides many out-of-the box solutions and tools, therefore minimizing external dependencies and considerably speeding up the development process. For these reasons it is best suited to the following:
- API backends for web and mobile applications
- Apps that require high security from cyber attacks (see above list of benefits) - e.g. FinTech digital products
- Apps which require a high level of customization - e.g. social media or gaming sites
- Apps in which you want to integrate a level of AI - e.g. pollution trackers
- Apps which use open-source software
Top websites which feature elements written in Django are: Pinterest, NASA, Spotify and The Guardian.
When might Django not be your top choice?
There are some scenarios in which Django definitely wouldn’t be your top choice. Below are just a few:
- Small, simple apps not requiring a database - for this another framework, such as Flask is likely to be better suited.
- Very large apps which cannot be built in a single codebase - here you might want to break your product up into microservices which use different frameworks or even different programming languages suitable for a particular piece of processing.
- When your team isn’t skilled in Python - here it would make much more sense to go with a technology with which you’re familiar.
What are the main alternatives to Django today?
Serverless computing is hot right now. With the cloud provider dynamically managing the allocation of resources, it is highly cost-effective, as pricing is based on the actual amount of resources consumed, rather than pre-purchased units of capacity. Serverless computing can also simplify the process of deploying code into production, which is why many programmers are turning to it. By using building blocks from the cloud provider of your preference it is possible to build the entire application: API, data processing pipeline, storage and all.
Another key trend is asynchronous programming, which has actually been around for a long time, but in recent years, has become more widely used. Asynchronous programming allows a unit of work to run separately from the primary application thread. There are numerous benefits to using it, such as improved application performance and enhanced responsiveness.
Django in 2020 and beyond
So what can we say about Django in its birthday speech? Well, Django, you have been quick, transparent, secure, versatile and flexible over the years, and you have brought us some inspiring apps, which are used by millions today. For this we thank you.
Indeed, in 2020 for most use cases, monolithic Django architecture is the way to go, battle tested, with a large community and a wealth of freebies.
And it’s parent, Python, has certainly been growing in popularity for the past few years. As of 2018, Django was ranked among the best frameworks by Python developers alongside Flask - click here to read our comparison of the two Python frameworks.
With this in mind, we can safely say that Django will be one of the major players in the web space down the road.
But having said that, do not get stuck with Django - stay on top of the latest tech developments and research alternatives, so that when your use case requires something more, you will know where to turn.