This post is an extract from my new book – Build Your First Website with Python and Django.
For your chance to join the launch team and get a 50% discount when the book is launched, see the end of this post.
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.
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.
So why Django?
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:
- Batteries included
- Doesn’t get in your way
- Built-in admin
- Battle tested
- Packages, packages and more packages!
- Actively developed
- Stable releases
- First class documentation
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:
- Python is second only to node.js in growth over the last five years. PHP, Java and Ruby have all declined in popularity.
- Python is now more common than PHP.
- Python jobs pay better than traditional Microsoft jobs (C#, C++, VBA and .NET).
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:
- admin—the Django administration application
- auth—Django’s authentication framework
- contenttypes—a framework for hooking into Django models
- flatpages—a framework for managing special case pages like site policies and terms and conditions of use
- gis—adds geospatial capabilities to Django
- humanize—adds template filters to improve readability of data
- messages—a framework for managing session- and cookie-based messages
- postgres—postgreSQL database specific features
- redirects—manages redirects
- sessions—a framework for managing anonymous sessions
- sites—allows you to operate multiple websites from the one installation
- sitemaps—implements sitemap XML files
- syndication—a framework for generating syndication feeds
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.
Doesn’t get in your way
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:
- Run separate servers for your database, applications and media;
- Easily have your media served from a Content Delivery Network (CDN);
- Cache content at multiple levels and scopes; and
- For really big sites, employ clustering and load-balancing to distribute your website across multiple servers.
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.
Packages, packages and more packages!
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:
- Wagtail, Mezzanine and django CMS content management systems
- Cookiecutter—quick and easy setup of Django project and app structures for more advanced applications
- Django ReST Framework—Implements a ReST API in Django
- Django allauth—Facebook, GitHub, Google and Twitter authentication for your Django apps
- Debug toolbar—display debug information as your project is running
- Django Celery—provides Celery integration for Django
- Oscar, Django Shop and Cartridge—eCommerce frameworks for Django (Cartridge is an extension for Mezzanine CMS)
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.
First class documentation
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.
Want my new Django book for beginners for half price?
I have a new book for beginners coming out very soon (by end of June if all goes to plan!).
In this new book I answer the big questions I get from beginners:
- Why should I use Django?
- What problems does Django help me solve?
- What if I don’t know Python?
- Please, can you give me something real? Something I can build and show off to my friends, or a potential employer – not just snippets like everyone else on the Internet?
Written for Django 1.11 and Python 3.6, the book teaches you to program using the absolute latest version of Django and Python.
By the end of the book you will not only know all of the basics to writing an awesome Django website, but you will have a functioning website ready for deployment, or to demonstrate to an employer – Or to show off to your friends 🙂
Anyone who signs up below will not only get to be a part of an exciting book launch, but will get the eBook version for half price as a part of a limited time launch special!
Join the Djangobook Family
Updates, freebies, discounts and more!