There is little doubt that Django is only one of many web frameworks available.
However, over the last decade, Django has distinguished itself as one of the leading frameworks for developing scalable, secure and maintainable web applications.
This is no fluke.
This post is an extract from my new book – Build Your First Website with Python and Django.
Django is not the outcome of an academic exercise, or the brainchild of a developer who thought they could do things better.
Django was created in a newsroom environment, where “today” is much more important than “clever”.
Although how Django achieves many complex tasks in such a simple way could be considered very clever, Django’s primary focus on getting stuff done is baked into its DNA.
Programming, like most creative pursuits, has many dedicated people who wear their passions on the outside.
It’s for this reason that I am very wary of This Software vs. That Software comparisons. Bottom line is, all programming languages, and the tools and frameworks built on them, have good points and bad points.
It’s my firm belief that the only versus worth considering is pragmatism vs. perfection.
Or to put it another way, do you want stable, maintainable code that you can deliver to a deadline, or do you want a box of arcane magic and boilerplate that will simultaneously make college professors love you and maintainers hate you?
Django has its rough edges for sure, but its pragmatic approach to getting stuff done is where it really stands out from the crowd. Django has plenty of supporters and a few detractors, so feel free to come to your own conclusions, however if you want my humble opinion, these are Django’s Top 10:
Python is arguably the easiest programming language to learn.
With its use of natural language constructs (e.g. paragraph-like layout and indentation) and simple to learn syntax, Python makes understanding program structure and flow significantly easier to learn than other popular languages.
This is evident in the fact that the greater proportion of introductory programming courses in universities and colleges now use Python as the language of choice.
Python is versatile. It runs websites and is used in many popular desktop applications on PCs and Macs. It can also be found in mobile applications and embedded in many devices. Python is also a popular scripting language for other applications.
Learning Python will almost certainly serve you no matter where your career takes you.
Python is popular. Google, one of the world’s biggest businesses, uses Python in many of its applications. It’s also used widely by professional programmers.
Some interesting facts out of the 2017 Stack Overflow Developer Survey:
Django inherits its “batteries included” philosophy from Python.
This is often interpreted as meaning that Django includes a lot of extra stuff you probably won’t need, however, the better analogy is that, instead of having to open up the language to insert your own power (batteries), you just have to flick the switch and Django does the rest.
In practical terms this means that Django implements some common, but complex processes by providing simple tools and wrappers to hide the complexity without compromising power.
Django’s “batteries” are located in the contrib packages. The contrib packages are:
The contrib packages can get a bit complex, so we will only be touching on one or two of them in this book, however as you can see, Django provides a solid list of powerful modules built-in so you don’t have to create them yourself.
When you create a Django application, Django adds no boilerplate, cruft or unnecessary functions. There are no mandatory imports, no required third-party libraries and no XML configuration files.
This can be a bit terrifying when you first create a Django project, as Django’s automatic tools (
startapp) only create a basic settings file, a few folders and some almost empty starter files.
While this might appear to be a bad thing, it’s actually a great benefit as Django has provided you with a solid foundation that you can build upon in any way you like.
The result is greater confidence in your code as you know that whatever is in your application, you put there.
Out of the box, Django provides you with an administration interface for working with your models and managing users, user permissions and groups.
The model interface immediately replaces the need for a separate database administration program for all but advanced database functions.
With very simple changes to your admin configuration, you can organize your model fields, show and hide fields, sort, filter and arrange your data to maximize your efficiency.
The admin also has an optional model documentation feature that provides automatic documentation of your models.
User management is always important in a modern website and Django provides all that you would expect—add and modify users, change passwords, create user groups, assign permissions and communicate with users.
Like the rest of Django, the admin is also customizable and extendable.
For example, admin display templates can be overridden and new functionality added for tasks like exporting your model data to a comma-delimited (CSV) file.
Django is based on the Model-View-Controller (MVC) design pattern. This means that database, program code (back-end) and display code (front-end) are separate.
These design philosophies allow you to:
Django supports a range of popular third-party vendors for web servers, performance management, caching, clustering and balancing.
It also supports major email and messaging applications and services like OAuth and ReST.
A good way to tell if any web framework is both robust and reliable is to find out how long it has been around, if it’s growing and what high-profile sites are using it.
Django was first open-sourced in 2005, after running for several years in the high demand environment of a news organization.
After nearly 12 years of growth, Django now not only runs news publishing companies like the Washington Post, but is also running all or part of major global enterprises like Pinterest, Instagram, Disqus, Bitbucket, EventBrite and Zapier.
Django continues to grow in popularity. Djangosites lists over 5200 sites using Django, and that is only for sites that register with Djangosites.
It would be impossible to guess how many pages Django serves every day compared to other technologies on the Internet, but that is largely irrelevant—Django has proven itself over the last 12 years by running some of the most heavily trafficked sites on the Internet, and continues to grow its user-base today.
Just about anything you are likely to want to do with Django has been done before.
Many of Django’s large international community of developers give back to the community by releasing their projects as open-source packages.
The largest repository of these projects can be found on the Django Packages site. At the time of writing, Django Packages lists over 3400 reusable Django apps, sites and tools to use in your own Django projects. A quick tour of popular packages includes:
With thousands more packages just like these, it’s highly likely that you will find a package that suits your needs, without having to reinvent the wheel.
One of the biggest risks of open source is whether there is sufficient interest in the project for it to attract developer support in the long term.
There is no such risk with Django—not only is the project over 12 years old, it has a long history of consistent releases and it continues to be supported by an active community and a large core team of voluntary contributors who maintain and improve the code base every day.
Django had it’s first production release in 2008 (version 1.0) and has had three Long Term Support (LTS) releases—1.4, 1.8 and 1.11. The 1.11 LTS release (current release) has full support out to the middle of 2020.
The Django development team maintains a development roadmap on the Django Project website and have a solid track record of meeting roadmap milestones.
The Django Project is also supported by an independent foundation—the Django Software Foundation—that is a registered non-profit in the US.
Open-source software projects are, in many cases, more actively developed and more secure than competing proprietary software.
The downside of the ever-evolving development of an open-source software project is the lack of a stable codebase on which to base commercial development.
Django addresses this issue with Long Term Support (LTS) versions of the software and a defined release process.
LTS versions are released with a guaranteed (typically three years) support period. In this period the codebase is guaranteed to remain stable; with patches for bugs, security and data loss 100% compatible with the feature release.
Django’s release process ensures that official releases are as stable as possible. After a development phase, each release enters an Alpha phase where a feature freeze is applied.
The new release then moves through Beta and Release Candidate (RC) stages where bugs are worked out of the release. If no major bugs are found for a period after the release candidate, the final will be released (feature release).
After the final has been released, only bugfixes and security patches are applied. These patches, like the LTS versions, are 100% compatible with the feature release.
Even in the very early releases, Django’s developers made sure that the documentation was comprehensive and that tutorials were easy to follow.
For me, the documentation should be number one on this list because it was the quality of the documentation that made me choose Django over other options.
This was in 2007 when Django was still version 0.96—before it had made its first official release. The official documentation has only got better in the intervening years.
Django also has strong support from community members who produce free learning materials, books, paid and free courses and lots of tips, tricks and assistance on their websites.
In this chapter we have considered the reasons why you would use Django to develop websites for yourself and your clients.
Django is not the only web framework available, but there are some very strong reasons why it’s one of the most popular.
With a strong design philosophy, robust scalability, security and huge community support, Django now runs some of the most recognised, high traffic enterprises on the internet.
With a large core team supporting it, Django will also continue to grow in the future.
In the next chapter, we will explore the actual mechanics of how Django works. We will do this from a high level, avoiding digging into code right away so you can gain an understanding of how all the different pieces fit together to make your Django website work.
This post is an extract from my new book – Build Your First Website with Python and Django.