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.
For example, authentication, URL routing, a template engine, an object-relational mapper(ORM), 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 one.
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 good 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 books and tutorials
There are a slew of free or low cost resources out there for Django. Since Django was released over 10 years ago and has had a huge number of updates since then, when you’re looking for an up-to-date Django book check out the list below or read this post showing current Django books as of Django 1.9.
- 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. It’s recently been updated for Django 1.7!
- The Django Girls Tutorial is a great tutorial that doesn’t assume any prior knowledge of Python or Django while helping you build your first web application.
- 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.
- This tutorial shows how to create a Django web app that can make phone calls and send text messages for automated surveys. The code is a really good example of a full Django project and is also available open source on GitHub.
- Effective Django is another free introduction to the web framework.
- The Django subreddit often has links to the latest resources for learning Django and is also a good spot to ask questions about it.
- Steve Losh wrote an incredibly detailed Django Advice guide.
- Lightweight Django has several nice examples for breaking Django into smaller simpler components.
- The Definitive Guide to Django Deployment explains the architecture of the resulting set up and includes Chef scripts to automate the deployment.
- This step-by-step guide for Django shows how to transmit data via AJAX with JQuery.
- 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, 1.7, or 1.8) project from scratch?”
- This Django tutorial shows how to build a project from scratch using Twitter Bootstrap, Bower, Requests and the Github API.
- 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.
- This Python Social Auth for Django tutorial will show you how to integrate social media sign in buttons into your Django application.
- Luke Plant writes about his approach to class based views (CBVs), which often provoke heated debate in the Django community for whether they are a time saver or “too much magic” for the framework.
- How to serve Django apps with uWSGI and Nginx on Ubuntu 14.04 and how to set up Django with PostgreSQL, Nginx and Gunicorn are detailed tutorials that walk through each step in the deployment process.
- Working with time zones is necessary for every web application. This blog post on pytz and Django is a great start for figuring out what you need to know.
Are you looking for Django videos in addition to articles? There is a special section for Django and web development on the best Python videos page.
- Paul Hallett wrote a detailed Django 1.7 app upgrade guide on the Twilio blog from his experience working with the django-twilio package.
- 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.
- Django migrations without downtimes shows one potential way of performing on-line schema migrations with Django.
Channels in 1.9+
Channels are a new mechanism in Django 1.9 provided as a standalone app. They may be incorporated into the core framework in 2.0+. Channels provide “real-time” full-duplex communication between the browser and the server based on WebSockets.
- This tutorial shows how to get started with Django Channels in your project.
- The channels examples repository contains a couple of good starter projects such as a live blog and a chat application to use as base code.
- Channnels currently use Django’s existing authentication scheme, but this blog post JSON Web Tokens authentication on Django Channels shows how to use a custom JSON Web Token (JWT) implementation in Django Channels instead.
- Offloading work using Django Channels is a short post that builds on a previous example to add a shared canvas with group updates via Channels, which would otherwise be difficult to accomplish in a Django web app without a persistent data transfer mechanism.
- Integrating 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.
- Getting Started with Django Testing will help you stop procrastinating on testing your Django projects if you’re uncertain where to begin.
- Testing in Django provides numerous examples and explanations for how to test your Django project’s code.
- Django views automated testing with Selenium gives some example code to get up and running with Selenium browser-based tests.
Django with Angular (Djangular) resources
- Getting Started with Django Rest Framework and AngularJS is a very detailed introduction to Djangular with example code.
- Building Web Applications with Django and AngularJS is a very detailed guide for using Django as an API layer and AngularJS as the MVC front end in the browser.
- This end to end web app with Django-Rest-Framework & AngularJS part 1 tutorial along with part 2, part 3 and part 4 creates an example blog application with Djangular. There is also a corresponding GitHub repo for the project code.
- Django-angular is a code library that aims to make it easier to pair Django with AngularJS on the front end.
Django ORM resources
Django comes with its own custom object-relational mapper (ORM) typically referred to as “the Django ORM”. Learn more about the Django ORM on the Python object-relational mappers page that includes a section specifically for the Django ORM as well as additional resources and tutorials.
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.
- How to Optimize Images for Page Load Speed in Django reviews good practices for improving page speed performance when media images make up a significant percentage of webpage download size.
- Using Amazon S3 to Store your Django Site’s Static and Media Files is a well written guide to a question commonly asked about static and media file serving.
- Loading Django FileField and ImageFields from the file system shows how to load a model field with a file from the file system.
- Restricting access to user-uploaded files in Django provides a protection mechanism for media files.
Open source Django example projects
- Browser calls with Django and Twilio shows how to build a web app with Django andTwilio Client to turn a user’s web browser into a full-fledged phone. Pretty awesome!
- 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 repositories 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
Project templates, not to be confused with a template engine, generate boilerplate code for a base Django project plus optional libraries that are often used when developing web applications.
- Caktus Group’s Django project template is Django 1.6+ ready.
- Cookiecutter Django is a project template from Daniel Greenfeld, for use with Audrey Roy’s Cookiecutter. The template results are Heroku deployment-ready.
- Two Scoops Django project template is also from the PyDanny and Audrey Roy. This one provides a quick scaffold described in the Two Scoops of Django book.
- Sugardough is a Django project template from Mozilla that is compatible with cookiecutter.
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 good 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 app runs but looks awful. How do I style the user interface?
How do I integrate existing web APIs into my application?
I’ve built a Python web app, now how do I deploy it?