1. Home
  2. Blog
  3. Tutorials

Django Installation Guide

Overview

This document provides step-by-step instructions for installing Django, setting up a virtual environment, creating a Django project, and running the development server.


Prerequisites

Before installing Django, ensure that the following software is installed on your system:

  • Python 3.8 or later
  • pip (Python package manager)

Verify Python Installation

Open a terminal or command prompt and run:

python --version

or

python3 --version

Expected output:

Python 3.x.x

Verify pip Installation

pip --version

Expected output:

pip x.x.x from ...


Step 1: Create a Virtual Environment

Using a virtual environment is recommended to isolate project dependencies.

Create the Environment

python -m venv venv

This creates a folder named venv containing the virtual environment.

Activate the Environment

Windows

venv\Scripts\activate

macOS/Linux

source venv/bin/activate

After activation, your terminal prompt should display the environment name.

Example:

(venv) C:\Projects>


Step 2: Install Django

Install Django using pip:

pip install django

Alternatively:

python -m pip install django

Verify Installation

django-admin --version

Example output:

5.2.1


Step 3: Create a Django Project

Create a new Django project:

django-admin startproject myproject

Navigate to the project directory:

cd myproject

Project structure:

myproject/
│
├── manage.py
└── myproject/
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    ├── asgi.py
    └── wsgi.py


Step 4: Run the Development Server

Start the Django development server:

python manage.py runserver

Expected output:

Watching for file changes with StatReloader
Starting development server at http://127.0.0.1:8000/

Open your browser and visit:

http://127.0.0.1:8000/

You should see the Django welcome page.


Step 5: Create a Django Application

Inside the project directory, create an app:

python manage.py startapp myapp

Project structure:

myproject/
│
├── manage.py
├── myapp/
│   ├── admin.py
│   ├── apps.py
│   ├── models.py
│   ├── views.py
│   └── migrations/
│
└── myproject/


Step 6: Register the Application

Open settings.py and add the application name to INSTALLED_APPS:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myapp',
]


Step 7: Apply Database Migrations

Run:

python manage.py migrate

Expected output:

Applying contenttypes...
Applying auth...
Applying admin...

This creates the default database tables.


Common Commands

CommandDescription
python manage.py runserverStart development server
python manage.py startapp appnameCreate a new app
python manage.py makemigrationsCreate migration files
python manage.py migrateApply migrations
python manage.py createsuperuserCreate admin user
python manage.py shellOpen Django shell

Troubleshooting

pip Not Found

Install pip:

python -m ensurepip --upgrade

Django Not Recognized

Verify installation:

pip show django

If Django is not installed:

pip install django

Virtual Environment Not Activating

Ensure that the correct activation command is used for your operating system.


Additional Resources


Conclusion

You have successfully:

  1. Installed Python and pip.
  2. Created a virtual environment.
  3. Installed Django.
  4. Created a Django project.
  5. Started the development server.
  6. Created and registered a Django application.
  7. Applied database migrations.

Your Django development environment is now ready for building web applications.

Need a hand with this?

Let our engineers take it from here