Fork me on GitHub

Django

Django is a widely used Python web application framework with a "batteries-included" philosophy. The principle behind batteries-included is that the common functionality for building web applications should come with the framework instead of as separate libraries.

Official Django logo. Trademark Django Software Foundation.

For example, authentication, URL routing, a templating system, an object-relational mapper, and database schema migrations (as of version 1.7) are all included with the Django framework. Compare that included functionality to the Flask framework which requires a separate library such as Flask-Login to perform user authentication.

The batteries-included and extensibility philosophies are simply two different ways to tackle framework building. Neither philosophy is inherently better than the other.

Why is Django a good web framework choice?

The Django project's stability, performance and community have grown tremendously over the past decade since the framework's creation. Detailed tutorials and best practices are readily available on the web and in books. The framework continues to add significant new functionality such as database migrations with each release.

I highly recommend the Django framework as a starting place for new Python web developers because the official documentation and tutorials are some of the best anywhere in software development. Many cities also have Django-specific groups such as Django District, Django Boston and San Francisco Django so new developers can get help when they are stuck.

There's some debate on whether learning Python by using Django is a bad idea. However, that criticism is invalid if you take the time to learn the Python syntax and language semantics first before diving into web development.

Django tutorials

  • Tango with Django is an extensive set of free introductions to using the most popular Python web framework. Several current developers said this book really helped them get over the initial framework learning curve.

  • 2 Scoops of Django by Daniel Greenfeld and Audrey Roy is well worth the price of admission if you're serious about learning how to correctly develop Django websites.

  • Effective Django is another free introduction to the web framework.

  • Test-Driven Development with Python focuses on web development using Django and JavaScript. This book uses the development of a website using the Django web framework as a real world example of how to perform test-driven development (TDD). There is also coverage of NoSQL, websockets and asynchronous responses. The book can be read online for free or purchased in hard copy via O'Reilly.

  • The Django subreddit often has links to the latest resources for learning Django and is also a good spot to ask questions about it.

  • Lincoln Loop wrote a Django Best Practices guide for the community.

  • Steve Losh wrote an incredibly detailed Django Advice guide.

  • Lightweight Django has several nice examples for breaking Django into smaller simplier components.

  • The Definitive Guide to Django Deployment explains the architecture of the resulting set up and includes Chef scripts to automate the deployment.

  • Deploying a Django app on Amazon EC2 instance is a detailed walkthrough for deploying an example Django app to Amazon Web Services.

  • This step-by-step guide for Django shows how to transmit data via AJAX with JQuery.

  • Deploying Django on AWS is another walkthrough for deploying Django to AWS.

  • django-awesome is a curated list of Django libraries and resources.

  • Starting a Django Project answers the question, “How do I set up a Django (1.5, 1.6, or /1.7) project from scratch?”

  • The recommended Django project layout is helpful for developers new to Django to understand how to structure the directories and files within apps for projects.

  • The Django Request-Response Cycle explains what happens when you visit a webpage generated by Django.

Django videos

Django 1.7-specific resources

  • Paul Hallett wrote a detailed Django 1.7 app upgrade guide on the Twilio blog from his experience working with the django-twilio package.

  • Designing Django's Migrations covers Django 1.7's new migrations from the main programmer of South and now Django's built-in migrations, Andrew Godwin.

  • Real Python's migrations primer explores the difference between South's migrations and the built-in Django 1.7 migrations as well as how you use them.

  • Andrew Pinkham's "Upgrading to Django 1.7" series is great learning material for understanding what's changed in this major release and how to adapt your Django project. Part 1, part 2 and part 3 and part 4 are now all available to read.

  • Integerating Front End Tools with Django is a good post to read for figuring out how to use Gulp for handling front end tools in development and production Django sites.

Django with Angular (Djangular) resources

Django ORM resources

The Django ORM works well for simple and medium-complexity database operations. However, there are often complaints that the ORM makes complex queries much more complicated than writing straight SQL or using SQLAlchemy.

It's technically possible to drop down to SQL but it ties the queries to a specific database implementation. The ORM is coupled closely with Django so replacing the default ORM with SQLAlchemy is currently a hack workaround. Note though that some of the Django core committers believe it is only a matter of time before the default ORM is replaced with SQLAlchemy. It will be a large effort to get that working though so it's likely to come in Django 1.9 or later.

Since the majority of Django projects are tied to the default ORM, it's best to read up on advanced use cases and tools for doing your best work within the existing framework.

  • Django models, encapsulation and data integrity is a detailed article by Tom Christie on encapsulating Django models for data integrity.

  • Django Debug Toolbar is a powerful Django ORM database query inspection tool. Highly recommended during development to ensure you're writing reasonable query code. Django Silk is another inspection tool and has capabilities to do more than just SQL inspection.

  • Making a specific Django app faster is a Django performance blog post with some tips on measuring performance and optimizing based on the measured results.

  • Why I Hate the Django ORM is Alex Gaynor's overview of the bad designs decisions, some of which he made, while building the Django ORM.

  • Going Beyond Django ORM with Postgres is specific to using PostgreSQL with Django.

  • Migrating a Django app from MySQL to PostgreSQL is a quick look at how to move from MySQL to PostgreSQL. However, my guess is that any Django app that's been running for awhile on one relational database will require a lot more work to port over to another backend even with the power of the ORM.

  • Django Model Descriptors discusses and shows how to incorporate business logic into Django models to reduce complexity from the views and make the code easier to reuse across separate views.

Static and media files

Deploying and handling static and media files can be confusing for new Django developers. These resources along with the static content page are useful for figuring out how to handle these files properly.

Open source Django example projects

  • Txt 2 React is a full Django web app that allows audiences to text in during a presentation with feedback or questions.

  • Openduty is a website status checking and alert system similar to PagerDuty.

  • Courtside is a pick up sports web application written and maintained by the author of PyCoder's Weekly.

  • These two Django Interactive Voice Response (IVR) system web application repositorities part 1 and part 2 show you how to build a really cool Django application. There's also an accompanying blog post with detailed explanations of each step.

  • Taiga is a project management tool built with Django as the backend and AngularJS as the front end.

Django project templates

Django learning checklist

Install Django on your local development machine.

Work through the initial "polls" tutorial.

Build a few more simple applications using the tutorial resources found in the "Django resources" section.

Start coding your own Django project with help from the official documentation and resource links below. You'll make plenty of mistakes which is critical on your path to learning the right way to build applications.

Read 2 Scoops of Django to understand Django best practices and learn better ways of building Django web applications.

Move on to the deployment section to get your Django project on the web.

What do you need to learn next for your Django app?

My user interface looks terrible. How do I style a web application?

I want to integrate external APIs into my Django project.

How do I deploy a Django web app once it's coded?

How can I version and store my source code so I don't lose it?


Interested in a complete Full Stack Python book with detailed tutorials and example code? Sign up here and you'll get an alert email if a book is created. No other emails will be sent other than sign up confirmation.