When we develop the server side of our web applications at INMAGIK, the python based Django web framework is our preferred choice. Django has become a strong technological foundation for us, with lots of success stories in our last three years of web development.
Personally, I've been following and using Django from my very first steps in web development, around 2007, and it helped me a lot, not only as a tool to build websites, but also as a huge resource for learning about web development and python programming.
In this short, hopefully not too technical post, I'll try to give you ten reasons to consider this framework. Of course, like every other tool and library, there might better solutions for each use case, but if you're developing a website and accessing mostly SQL databases with any other language or framework, you should give Django a chance.
Moreover, this is a great time for the django framework, as it has reached stability and provides a great set of features, still being in a very active phase of development with great plans for the near future.
Python remains, in my opinion, one of the most readable programming languages. It's available for many platforms and operating systems and has a very powerful standard library. Long time Pythoneer Tim Peters succinctly channels the BDFL's guiding principles for Python's design:
The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
(if you have python installed you can start an interpreter and type
import this see the Zen of Python in your python console).
One of reasons I like Django so much is that it is really "pythonic" and makes great use of the language features, such as metaclasses used for implementing the django ORM, the database access layer.
In general, the Django APIs, are well structured, elegant and allow a very clean and concise programming style, stressing out very much the DRY principle (Don't Repeat Yourself).
Django is an open source framework coming with a very permissive license in terms of commercial usage. With its first release in 2005, it's a very mature project and it's maintained by an awesome group of volunteers, the Django software foundation.
The project provides a well documented release process, with long term support releases (LTS) that will get security and data loss fixes applied for a guaranteed period of time, typically three years, a reasonable amount of guaranteed lifetime for a modern web application.
As a long term django user I can say that the majority of the API is probabily stable since 1.0, with really smooth changes between, well anticipated by a clear deprecation policy.
Since the very beginning of the project, django documentation has always been complete and very user friendly, also for newcomers in web development, thanks to its many examples and tutorials.
Compared to other open source frameworks, we had the need to look into the source code of django just a few times in our everyday use, as the documentation covers all the django APIs is a very detailed way, from the very basic use case to the most advanced ones. As explained in the docs, django documentation offers different levels of reading:
The Django framework contains different python packages, being effectively many different frameworks for addressing the various tasks of web development in a modular way.
Between many others, we have for example:
Such modularity helps developer building different kind of web applications, with rich APIs for dealing with all the common use cases. These sub-frameworks and packages are sometimes referred as "backends", as they abstract some groups of functionalities, that can be completely turned off or swapped in favour of other implementations.
Moreover, all these packages and "backends" provide great APIs allowing easy composition of features, extension and custom implementations for almost every part of the Django framework as a whole.
One notable example of these frameworks is the GIS framework
django.contrib.gis, a very powerful set of tools to handle geographic information, that comes with the standard django installation.
The python standard library is one of the most complete I know of, but the success of Python, in particular in the field of data science, is highly related to the availability of third party packages (for example numpy for advanced math and pandas for data analysis). Here you can find an exhaustive list of interesting python packages.
In a django project, the separation of concerns is encouraged by letting you split the various features of your web applications into "reusable apps", that are just python packages. This helps a lot with code organization and to allow reuse of code. These apps can live just in your project code, or be distributed like any other python package and installed in the project as external dependencies.
This approach has led to the proliferation of many specialized reusable apps, from very low level features to ready-to-use intefaces.
These some of the notable third parties app we often use at INMAGIK:
Django is a very general framework for building web applications, but it really shines when dealing with SQL databases.
The ORM (Object Relational Mapper) is one of the most powerful parts of Django, and can be described as a layer between the database(s) and your application, with an elegant and powerful API for defining, accessing and maintaining your data from in python code.
These are some of the key features of the ORM:
CREATE TABLE...SQL statements. As it's python code, this model is also available for introspection in your application (for example, you can cycle all the fields of a data model or know the data type of a certain field)
At INMAGIK we normally use PostgreSQL as database backend, for its reliability, extensions, great support and availability of commercial support and providers.
Django has an extended support for the PostgresSQL backend, with its
django.contrib.postgres package, that contains model fields and form fields for a number of PostgreSQL specific data type.
During our project development at INMAGIK, we met two great usecases for django + postgres:
django.contrib.gis.db.backends.postgisbackend, that will give you access postgis, a powerful postgres extension for dealing with geographic data, from the django ORM.
Migrations are still part of the Django ORM, but this feature deserves a point on its own.
The SQL (relational) data model has many advantages when writing applications, as it provides a very structured way to access data, allowing us to define constraints about the shape and relations of records. Once a record has been "accepted" by a well structured SQL database, we can safely rely on our constraints to build complex logic that manipulates data.
This comes at the cost of using a dedicate set of SQL instructions for data definition (
CREATE/ALTER TABLE, CREATE/ALTER INDEX, CREATE/ALTER CONSTRAINTS, ...) and imperatively maintaining our tables as the application evolves.
Django features the powerful migrations framework, born as a third party app called South and merged into the django core by Andrew Godwin, the principal maintainer of South and django core team member. This framework helps you by detecting changes in your data models declarations and generates automatically SQL statements to adapt the database schema. It also provides the ability to create "data migrations" to apply transformations to your existing data in a predictable way.
This is a real killer feature of the django framework, and I never found something comparable in other web frameworks. The SQL data model is something that will evolve with your application (very fast in the development stage, but also in production when you will add new features), so be prepared to manage these changes.
Take a look at the topic guide on migrations from the django docs for all the details.
Django comes with the
django.contrib.admin package, a reusable app that enables a web based admininistration interface for your data models with just a few lines of code. The django admin is very interesting for many reasons:
The admin was not design to be used by final users, but in our experience it may be a good option, if you need a simple administation interface for some advanced users and you don't have a very complex data model. During development the admin interface may also be used for debugging and to put some data in your database.
Django was initially designed to handle one-way, syncronous, client-server "request-response" interactions based on the HTTP protocol. Django's primary deployment platform has always been WSGI, the Python standard for web servers and applications: the Web Server Gateway Interface is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language.
This kind of design makes difficult to implement non-HTTP protocols such as websockets, common in modern web apps. To overcome such limitation, the Channels project was born. This project, which we are using in some of our projects for websocket support, "takes Django and extends its abilities beyond HTTP - to handle WebSockets,chat protocols, IoT protocols, and more. It’s built on a Python specification called ASGI."
Back to the django world, the DEP 0009: Async-capable Django by Andrew Godwin, proposes to add "support for asynchronous Python into Django, while retaining synchronous Python support as well in a backwards-compatible fashion ..." and that "..in the near future Django will add on support for asynchronous views, middleware, ORM, and other key pieces."
This process has started with the 3.0 relase of django, with ASGI support: as the docs say "Django 3.0 begins our journey to making Django fully async-capable by providing support for running as an ASGI application".
This is great news for all django users, as it opens new use cases and applications for the framework in the near future.
Django is part of the stack of many successful websites and applications used by millions of users, such as:
Django is an awesome python based web framework, mature, stable and packed with features allowing to build a wide range of web applications, from REST APIs and web services to server-side rendered websites.
At INMAGIK, in 2020 we'll continue to invest on django for and use in our stack, as it helps us building maintenable and extensible web apps and services for our clients.
Let us know what you think by tweeting at @inmagiklabs.