• Skip to main content
  • Select language
  • Skip to search
MDN Web Docs
  • Technologies
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs / DOM
    • WebExtensions
    • MathML
  • References & Guides
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
Learn web development
  1. MDN
  2. Learn web development
  3. Server-side website programming
  4. Django Web Framework (Python)
  5. Setting up a Django development environment

Setting up a Django development environment

In This Article
  1. Django development environment overview
    1. What is the Django development environment?
    2. What are the Django setup options?
      1. What operating systems are supported?
      2. What version of Python should you use?
      3. Where can we download Django?
      4. Which database?
      5. Installing system-wide or in a Python virtual environment?
  2. Installing Python 3
    1. Ubuntu 16.04
    2. Mac OS X
    3. Windows 10
  3. Installing Django
  4. Testing your installation
  5. Summary
  6. See also
Previous Overview: Django Next

 

Now that you know what Django is for, we'll show you how to set up 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.

Prerequisites: Know how to open a terminal / command line. Know how to install software packages on your development computer's operating system.
Objective: To have a development environment for Django (1.10) running on your computer.

Django development environment overview

Django makes it very easy to set up your own computer so that you can start developing web applications. This section explains what you get with the development environment, and provides an overview of some of your setup and configuration options. The remainder of the article explains the recommended method of installing the Django development environment on Ubuntu, Mac OS X, and Windows, and how you can test it.

What is the Django development environment?

The development environment is an installation of Django on your local computer that you can use for developing and testing Django apps prior to deploying them to a production environment.

The main tools that Django itself provides are a set of Python scripts for creating and working with Django projects, along with a simple development webserver that you can use to test local (i.e. on your computer, not on an external web server) Django web applications on your computer's web browser.

There are other peripheral tools, which form part of the development environment, that we won't be covering here. These include things like a text editor or IDE for editing code, and a source control management tool like Git for safely managing different versions of your code. We are assuming that you've already got a text editor installed.

What are the Django setup options?

Django is extremely flexible in terms of how and where it can be installed and configured. Django can be:

  • installed on different operating systems.
  • used with Python 3 and Python 2.
  • installed from source, from the Python Package Index (PyPi) and in many cases from the host computer's package manager application.
  • configured to use one of several databases, which may also need to be separately installed and configured.
  • run in the main system Python environment or within separate Python virtual environments.

Each of these options requires slightly different configuration and setup. The following subsections explain some of your choices. For the rest of the article we'll show you how to setup Django on a small number of operating systems, and that setup will be assumed throughout the rest of this module.

Note: Other possible installation options are covered in the official Django documentation. We link to the appropriate documents below.

What operating systems are supported?

Django web applications can be run on almost any machine that can run the Python programming language: Windows, Mac OS X, Linux/Unix, Solaris, to name just a few. Almost any computer should have the necessary performance to run Django during development.

In this article we'll provide instructions for Windows, Mac OS X, and Linux/Unix.

What version of Python should you use?

Django runs on top of Python, and can be used with either Python 2 or Python 3 (or both). When selecting a version you should be aware that:

  • Python 2 is a legacy version of the language that is no longer receiving new features but has a truly enormous repository of high quality 3rd party libraries for developers to use (some of which are not available for Python 3).
  • Python 3 is an update of Python 2 that, while similar, is more consistent and easier to use. Python 3 is also the future of Python, and continues to evolve.
  • It is also possible to support both versions using compatibility libraries (e.g. six), although not without additional development effort.

Note: Historically Python 2 was the only realistic choice, because very few 3rd party libraries were available for Python 3. The current trend is that most new and popular packages on the Python Package Index (PyPi) support both versions of Python. While there are still many packages that are only available for Python 2, choosing Python 3 is now a feasible option.

We recommend that you use the latest version of Python 3 unless the site depends on 3rd party libraries that are only available for Python 2.

This article will explain how to install an environment for Python 3 (the equivalent setup for Python 2 would be very similar).

Where can we download Django?

There are three places to download Django:

  • The Python Package Repository (PyPi), using the pip tool. This is the best way to get the latest stable version of Django.
  • Use a version from your computer's package manager. Distributions of Django that are bundled with operating systems offer a familiar installation mechanism. Note however that the packaged version may be quite old, and can only be installed into the system Python environment (which may not be what you want).
  • Install from source. You can get and install the latest bleeding-edge version of Python from source. This is not recommended for beginners, but is needed when you're ready to start contributing back to Django itself.

This article shows how to install Django from PyPi, in order to get the latest stable version.

Which database?

Django supports four main databases (PostgreSQL, MySQL, Oracle and SQLite), and there are community libraries that provide varying levels of support for other popular SQL and NOSQL databases. We recommend that you select the same database for both production and development (although Django abstracts many of the database differences using its Object-Relational Mapper (ORM), there are still potential issues that are better to avoid).

For this article (and most of this module) we will be using the SQLite database, which stores its data in a file. SQLite is intended for use as a lightweight database and can’t support a high level of concurrency. It is however an excellent choice for applications that are primarily read-only.

Note: Django is configured to use SQLite by default when you start your website project using the standard tools (django-admin). It's a great choice when you're getting started because it requires no additional configuration or setup. 

Installing system-wide or in a Python virtual environment?

When you install Python 3 on your computer you get a single global environment (set of installed packages) for your Python code, which you manage using the pip3 tool. While you can install whatever Python packages you like in this environment, you can only install one particular version at a time. This means that any changes you make to any Python application can potentially affect all others, and you can only have one Django environment/version at a time.

Experienced Python/Django developers often choose to instead run their Python apps within independent Python virtual environments. These allow developers to have multiple different Django environments on a single computer, allowing them to create new websites (using the latest version of Django) while still maintaining websites that rely on older versions. The Django developer team itself recommends that you use Python virtual environments!

When you're getting started the approach you use doesn't particularly matter. As the setup is a little easier, we've decided to show you how to install Django directly into the system-wide Python 3 environment.

Important: The rest of this article shows how to set up Django into the system-wide Python 3 environment, on Ubuntu Linux, Mac OS X, and Windows 10.

Installing Python 3

In order to use Django you will have to install Python 3 on your operating system. You will also need the Python Package Index tool — pip3 — which is used to manage (install, update, and remove) Python packages/libraries used by Django and your other Python apps.

This section briefly explains how you can check what versions are present, and install new versions as needed, for Ubuntu Linux 16.04, Mac OS X, and Windows 10.

Note: Depending on your platform, you may also be able to install Python/pip from the operating system's own package manager or via other mechanisms. For most platforms you can download the required installation files from https://www.python.org/downloads/ and install them using the appropriate platform-specific method.

Ubuntu 16.04

Ubuntu Linux includes Python 3 by default. You can confirm this by running the following command in the bash terminal:

python3 -V
 Python 3.5.2

However the Python Package Index tool you'll need to install packages for Python 3 (including Django) is not available by default. You can install pip3 in the bash terminal using:

sudo apt-get install python3-pip

Mac OS X

Mac OS X "El Capitan" does not include Python 3. You can confirm this by running the following commands in the bash terminal:

python3 -V
 -bash: python3: command not found

You can easily install Python 3 (along with the pip3 tool) from python.org:

  1. Download the required installer:
    1. Go to https://www.python.org/downloads/
    2. Select the Download Python 3.5.2 button (the exact minor version number may differ).
  2. Locate the file using Finder, and double-click the package file. Following the installation prompts.

You can now confirm successful installation by checking for the Python 3 as shown below:

python3 -V
 Python 3.5.20

You can similarly check that pip3 is installed by listing the available packages:

pip3 list

Windows 10

Windows doesn't include Python by default, but you can easily install it (along with the pip3 tool) from python.org:

  1. Download the required installer:
    1. Go to https://www.python.org/downloads/
    2. Select the Download Python 3.5.2 button (the exact minor version number may differ).
  2. Install Python by double-clicking on the downloaded file and following the installation prompts

You can then verify that Python was installed by entering the following text into the command prompt:

py -3 -V 
 Python 3.5.2

The Windows installer incorporates pip3 (the Python package manager) by default. You can list installed packages as shown:

pip3 list

Installing Django

Once you've installed Python 3 and pip3, you can use pip3 to install Django.

pip3 install django

You can test that Django is installed by running the following command (this just tests that Python can find the Django module):

# Linux/Mac OS X
python3 -m django --version
 1.10.10
# Windows
py -3 -m django --version 
 1.10.10

Note: On Windows you launch Python 3 scripts by prefixing the command with py -3, while on Linux/Mac OSX, the command is python3.

Important: The rest of this module uses the Linux command for invoking Python 3 (python3) . If you're working on Windows simply replace this prefix with: py -3

Testing your installation

The above test works, but it isn't very much fun. A more interesting test is to create a skeleton project and see it working. To do this, first navigate in your command prompt/terminal to where you want to store you Django apps. Create a folder for your test site and navigate into it.

mkdir django_test
cd django_test

You can then create a new skeleton site called "mytestsite" using the django-admin tool as shown. After creating the site you can navigate into the folder where you will find the main script for managing projects, called manage.py.

django-admin startproject mytestsite
cd mytestsite

We can run the development web server from within this folder using manage.py and the runserver command, as shown.

$ python3 manage.py runserver 
Performing system checks...
System check identified no issues (0 silenced).
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
September 19, 2016 - 23:31:14
Django version 1.10.1, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Note: The above command shows the Linux/Mac OS X command. You can ignore the warnings about  "13 unapplied migration(s)" at this point!

Once the server is running you can view the site by navigating to the following URL on your local web browser: http://127.0.0.1:8000/. You should see a site that looks like this:

The home page of the skeleton Django app.

Summary

You now have a Django development environment up and running on your computer.

In the testing section you also briefly saw how we can create a new Django website using django-admin startproject, and run it in your browser using the development web server (python3 manage.py runserver). In the next article we expand on this process, building a simple but complete web application.

See also

  • Quick Install Guide (Django docs)
  • How to install Django — Complete guide (Django docs) - includes information on how to remove Django
  • How to install Django on Windows (Django docs)

Previous Overview: Django Next

 

Document Tags and Contributors

Tags: 
  • Beginner
  • CodingScripting
  • Development environment
  • django
  • Installing
  • Intro
  • Learn
  • Python
 Contributors to this page: omideus, chrisdavidmills, educarneiro, BaderSur, hamishwillee
 Last updated by: omideus, Apr 14, 2017, 7:53:12 AM
See also
  1. Complete beginners start here!
  2. Getting started with the Web
    1. Getting started with the Web overview
    2. Installing basic software
    3. What will your website look like?
    4. Dealing with files
    5. HTML basics
    6. CSS basics
    7. JavaScript basics
    8. Publishing your website
    9. How the Web works
  3. HTML — Structuring the Web
  4. Introduction to HTML
    1. Introduction to HTML overview
    2. Getting started with HTML
    3. What's in the head? Metadata in HTML
    4. HTML text fundamentals
    5. Creating hyperlinks
    6. Advanced text formatting
    7. Document and website structure
    8. Debugging HTML
    9. Assessment: Marking up a letter
    10. Assessment: Structuring a page of content
  5. Multimedia and embedding
    1. Multimedia and embedding overview
    2. Images in HTML
    3. Video and audio content
    4. From object to iframe — other embedding technologies
    5. Adding vector graphics to the Web
    6. Responsive images
    7. Assessment: Mozilla splash page
  6. HTML tables
    1. HTML tables overview
    2. HTML table basics
    3. HTML Table advanced features and accessibility
    4. Assessment: Structuring planet data
  7. CSS — Styling the Web
  8. Introduction to CSS
    1. Introduction to CSS overview
    2. How CSS works
    3. CSS syntax
    4. Selectors introduction
    5. Simple selectors
    6. Attribute selectors
    7. Pseudo-classes and pseudo-elements
    8. Combinators and multiple selectors
    9. CSS values and units
    10. Cascade and inheritance
    11. The box model
    12. Debugging CSS
    13. Assessment: Fundamental CSS comprehension
  9. Styling text
    1. Styling text overview
    2. Fundamental text and font styling
    3. Styling lists
    4. Styling links
    5. Web fonts
    6. Assessment: Typesetting a community school homepage
  10. Styling boxes
    1. Styling boxes overview
    2. Box model recap
    3. Backgrounds
    4. Borders
    5. Styling tables
    6. Advanced box effects
    7. Assessment: Creating fancy letterheaded paper
    8. Assessment: A cool-looking box
  11. CSS layout
    1. CSS layout overview
    2. Introduction
    3. Floats
    4. Positioning
    5. Practical positioning examples
    6. Flexbox
    7. Grids
  12. JavaScript — Dynamic client-side scripting
  13. JavaScript first steps
    1. JavaScript first steps overview
    2. What is JavaScript?
    3. A first splash into JavaScript
    4. What went wrong? Troubleshooting JavaScript
    5. Storing the information you need — Variables
    6. Basic in JavaScript — Numbers and operators
    7. Handling text — Strings in JavaScript
    8. Useful string methods
    9. Arrays
    10. Assessment: Silly story generator
  14. JavaScript building blocks
    1. JavaScript building blocks overview
    2. Making decisions in your code — Conditionals
    3. Looping code
    4. Functions — Reusable blocks of code
    5. Build your own function
    6. Function return values
    7. Introduction to events
    8. Assessment: Image gallery
  15. Introducing JavaScript objects
    1. Introducing JavaScript objects overview
    2. Object basics
    3. Object-oriented JavaScript for beginners
    4. Object prototypes
    5. Inheritance in JavaScript
    6. Working with JSON data
    7. Object building practise
    8. Assessment: Adding features to our bouncing balls demo
  16. Accessibility — Make the web usable by everyone
  17. Accessibility guides
    1. Accessibility overview
    2. What is accessibility?
    3. HTML: A good basis for accessibility
    4. CSS and JavaScript accessibility best practices
    5. WAI-ARIA basics
    6. Accessible multimedia
    7. Mobile accessibility
  18. Accessibility assessment
    1. Assessment: Accessibility troubleshooting
  19. Tools and testing
  20. Cross browser testing
    1. Cross browser testing overview
    2. Introduction to cross browser testing
    3. Strategies for carrying out testing
    4. Handling common HTML and CSS problems
    5. Handling common JavaScript problems
    6. Handling common accessibility problems
    7. Implementing feature detection
    8. Introduction to automated testing
    9. Setting up your own test automation environment
  21. Server-side website programming
  22. First steps
    1. First steps overview
    2. Introduction to the server-side
    3. Client-Server overview
    4. Server-side web frameworks
    5. Website security
  23. Django web framework (Python)
    1. Django web framework (Python) overview
    2. Introduction
    3. Setting up a development environment
    4. Tutorial: The Local Library website
    5. Tutorial Part 2: Creating a skeleton website
    6. Tutorial Part 3: Using models
    7. Tutorial Part 4: Django admin site
    8. Tutorial Part 5: Creating our home page
    9. Tutorial Part 6: Generic list and detail views
    10. Tutorial Part 7: Sessions framework
    11. Tutorial Part 8: User authentication and permissions
    12. Tutorial Part 9: Working with forms
    13. Tutorial Part 10: Testing a Django web application
    14. Tutorial Part 11: Deploying Django to production
    15. Web application security
    16. Assessment: DIY mini blog
  24. Express Web Framework (node.js/JavaScript)
    1. Express Web Framework (Node.js/JavaScript) overview
    2. Express/Node introduction
    3. Setting up a Node (Express) development environment
    4. Express tutorial: The Local Library website
    5. Express Tutorial Part 2: Creating a skeleton website
    6. Express Tutorial Part 3: Using a database (with Mongoose)
    7. Express Tutorial Part 4: Routes and controllers
    8. Express Tutorial Part 5: Displaying library data
    9. Express Tutorial Part 6: Working with forms
    10. Express Tutorial Part 7: Deploying to production
  25. Further resources
  26. Advanced learning material
    1. WebGL: Graphics processing
  27. Common questions
    1. HTML questions
    2. CSS questions
    3. JavaScript questions
    4. How the Web works
    5. Tools and setup
    6. Design and accessibility
  28. How to contribute