Beginner Lesson 1: Why Django?

Why Django?

The first question people almost always ask when they’re introduced to Django is “why should I learn Django?”

“What is it about Django that makes it better than Framework X or language Y for building web applications.?”

Good question.

Programming, like most creative pursuits, has many dedicated people who wear their passions on the outside.

It’s for this reason that I’m 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.

When it comes to comparing Django with other web frameworks It’s my firm belief that the only comparison 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, 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 haters so feel free to come to your own conclusions.

However, if you want my humble opinion, these are Django’s Top 10:

Python

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 2021 Stack Overflow Developer Survey:

Python is the third most polular language behind HTML and JavaScript.

Python is the most wanted language among professional developers for the fifth year in a row.- Python is now twice as common than PHP.- Python jobs pay better than traditional Microsoft jobs (C#, C++, VBA and .NET).- Django is in the Top 10 most polular web frameworks, is twice as popular as Ruby on Rails and seven times as popular as Drupal.

Batteries Included

  • Python is the third most popular language behind HTML and JavaScript.
  • Python is the most wanted language among professional developers for the fifth year in a row.
  • Python is now twice as common than PHP.
  • Python jobs pay better than traditional Microsoft jobs (C#, C++, VBA and .NET).
  • Django is in the Top 10 most popular web frameworks, is twice as popular as Ruby on Rails, and beats Laravel by several places.

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 (startproject and 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.

Built-in admin

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.

Scalable

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.

Django takes this separation one step further by separating code from the static media—images, files, CSS and JavaScript—that make up your site.

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.

Battle tested

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 more than a decace 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 thousands of 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 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.

Like the Content? Grab the Book for as Little as $5!

Other than providing you with a convenient resource you can print out, or load up on your device, buying the book also helps support this site.

eBook bundle includes PDF, ePub and source and you only pay what you can afford.

Get the eBook bundle here.

You can get the paperback from Amazon.

Actively Developed

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 its first production release in 2008 (version 1.0) and has had five Long Term Support (LTS) releases—1.4, 1.8, 1.11, 2.2 and 3.2. The current LTS version, Django 3.2, will be supported until at least mid-2024. Django 4.0 was released in December 2021.

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.

Stable releases

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.

I am in this latter group—but there are plenty of others. A quick search of the Internet will return numerous free and paid Django resources to support your Django programming.

I am sure, as your Django programming career progresses, you will find your own reasons for loving how Django does things.

Of course, you are also going to discover things about Django that you find frustrating but, given every programming language and the frameworks built upon them have their idiosyncrasies, I am sure you will discover, as I have done, that when it comes to building secure and scalable websites quickly, Django’s benefits far out weight its challenges.

Up next…

Scroll to Top