Mozilla's getting a new look. What do you think?

Django Web Framework (Python)

This article needs an editorial review. How you can help.

This page is not complete.

Contact Hamish Willee via chrisdavidmills if you have any questions about this work.

Django is an extremely popular and fully featured server-side web framework, written in Python. The module shows you why Django is one of the most popular web server frameworks, how to set up a development environment, and how to get started with using it to create your own web applications.


Before starting this module you don't need to have any knowledge of Django. You will need to understand what server-side web programming and web frameworks are, ideally by reading the topics in our Server-side website programming first steps module.

A general knowledge of programming concepts and Python is recommended, but not essential to understanding the core concepts.

Note: Python is one of the easiest programming languages for novices to read and understand. That said, if you want to understand this module better then there are numerous free books and tutorials available on the Internet (new programmers might want to check out the Python for Non Programmers page on the wiki).


Django Introduction
In this first Django article we answer the question "What is Django?" and give you an overview of what makes this web framework special. We'll outline the main features, including some of the advanced functionality that we won't have time to cover in detail in this module. We'll also show you some of the main building blocks of a Django application, to give you an idea of what it can do before you then go on to set it up and start playing.
Setting up a Django development environment
Now that you know what Django is for, we'll show you how to setup and test a Django development environment on Windows, Linux (Ubuntu), and Mac OS X — whatever common operating system you are using, this article should give you what you need to be able to start developing Django apps.
Django Tutorial — The Local Library website
The first article in our practical tutorial series explains what you'll learn, and provides an overview of the "local library" example website we'll be working through and evolving in subsequent articles.
Django Tutorial (2/?): Creating a skeleton website
This article shows how you can create a "skeleton" website project as a basis, which you can then go on to populate with site-specific settings, urls, models, views, and templates.
Django Tutorial (3/?): Using models
This article shows how to define models for the LocalLibrary website — models represent the data structures we want to store our app's data in, and also allow Django to store data in a database for us (and modify it later on). It explains what a model is, how it is declared, and some of the main field types. It also briefly shows a few of the main ways you can access model data.
Django Tutorial (4/?): Django admin site
Now that we've created models for the LocalLibrary website, we'll use the Django Admin site to add some "real" book data. First we'll show you how to register the models with the admin site, then we'll show you how to login and create some data. At the end we show some of ways you can further improve the presentation of the admin site.
URL processing (TBD)
The previous article gave just a taste of how Django maps resource URLs to handler functions ("views"). Here we provide more information about how URL mapping works, how data can be extracted from URL patterns, and how you can pass data into a view.
Views and Request handling (TBD)
Django's views are where you write the "business logic" of each request handler — they receive HTTP requests and return formatted HTTP responses containing the requested content. This article explains what a view needs to do, and some of the ways you can go about writing them.
Templates and content formatting (TBD)
Django's templating system allows you to create a "standard layout" for your website pages, using placeholders to indicate where data will be inserted when a page is rendered. This topic shows the recommended way to create your layouts, along with an explanation of the most important parts of the template syntax.
Forms (TBD)
HTML Forms are used to collect user data and send it to a website for processing. Form handling can be complicated, and includes creating the HTML code for the form, validating the entered data on both the client and server, processing/storing the returned data, and returning a response. Django simplifies much of this work, and is even capable of reusing data defined in the model for creating a form — this article shows how.
Users, sessions, and authentication (TBD)
Django provides cookie-based middleware to support user accounts, access permissions, and sessions. Here we explain how to enable this middleware, and outline how to manage user logins/logout, access to functionality, and permissions.
Testing Django code (TBD)
For very basic sites with only a few lines of code, you may be able to get away with manual testing. As your site gets larger, an automated test suite can help to validate new code as it is written and is the only practical way to ensure that changes to not introduce new bugs. This article provides a very brief overview of the recommended way to write and run unit tests in your Django web application.
Django web application security (TBD)
Protecting user data is an essential part of any website design. We already explained some of the more common security threats in the topic Web security — this article builds on that information,  providing a brief overview of the security features that are provided for Django users out of the box.
Deployment to production (TBD)
Now that your web application is finished, you will want to upload it to a production server. To make this easier, here we help you find a hosting site that might meet your budget and scaling needs. We then explain some of the changes you need to make to hide any "development settings". Last of all we provide a real "worked example" of how you can install a web application, using hosting on the free tier of the Heroku cloud hosting service.


The following assessment will test your understanding of how to create a website using Django, as described in the guides listed above

DIY Mini Blog (TBD)
In this assessment you'll use some of the knowledge you've learned from this module to create your own blog.

Document Tags and Contributors

 Contributors to this page: hamishwillee, chrisdavidmills
 Last updated by: hamishwillee,