Django Get Started
Follow these steps to install Django inside an isolated virtual environment and launch your first project's development server.
Setting Up a Virtual Environment
Before installing Django, create an isolated Python environment for your project. A virtual environment keeps your project's dependencies separate from other projects and from your system-wide Python installation, preventing version conflicts between projects that need different Django versions.
- Python 3.10 or newer installed and available on your PATH
- pip, Python's package manager (bundled with modern Python installers)
- A terminal or command prompt you're comfortable working in
Example 1: Create and Activate a Virtual Environment
# Create the virtual environment
python -m venv env
# Activate it (macOS/Linux)
source env/bin/activate
# Activate it (Windows)
env\Scripts\activate
# Your prompt should now show (env)
(env) $ python --version
Python 3.12.3Installing Django
With the virtual environment active, install Django using pip. Because the environment is active, Django is installed only for this project rather than system-wide.
Example 2: Install and Verify Django
(env) $ pip install django
# Confirm the installed version
(env) $ python -m django --version
5.0.6Creating Your First Project
django-admin is a command-line utility installed alongside Django. Running startproject scaffolds a new project directory containing the settings and configuration files every Django site needs, and manage.py runserver starts a lightweight development web server.
Example 3: Start a New Project and Run the Server
(env) $ django-admin startproject mysite
(env) $ cd mysite
(env) $ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
Django version 5.0.6, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.Exercise: Django Get Started
Which command installs Django using pip?