Installing Django & Environment Setup0%

Installing Django & Environment Setup

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

Installing Django & Environment Setup

Django is a high-level Python web framework designed for rapid, secure, and maintainable software engineering. Following the "batteries-included" philosophy, Django ships out of the box with an Object-Relational Mapper (ORM), database migration engine, administrative dashboard, user authentication, and CSRF/XSS security protections.


1. Setting Up an Isolated Virtual Environment

Never install Python web frameworks into your global operating system environment. Dependency version conflicts between packages can break OS-level tools or other projects.

Bash / Terminal
# 1. Create a dedicated virtual environment
python -m venv venv
 
# 2. Activate virtual environment
# On macOS / Linux:
source venv/bin/activate
 
# On Windows (PowerShell):
.\venv\Scripts\Activate.ps1
# On Windows (CMD):
.\venv\Scripts\activate.bat

Verify that the active python binary points inside your virtual environment:

Bash / Terminal
which python # or 'Get-Command python' on Windows

2. Installing Django and Freezing Dependencies

Bash / Terminal
# Upgrade pip package installer
python -m pip install --upgrade pip
 
# Install latest production Django release
pip install django
 
# Verify Django installation and version
python -m django --version
 
# Freeze active dependencies into requirements.txt
pip freeze > requirements.txt

A clean requirements.txt enables deterministic dependency reproduction across teammates and staging/production Docker containers.


3. Creating the Project and Running the Local Dev Server

In Django terminology, a Project is a collection of configurations and applications for a given website.

Bash / Terminal
# Initialize a new Django project named 'config' inside the current directory
django-admin startproject config .
 
# Apply initial core migrations (auth, contenttypes, sessions)
python manage.py migrate
 
# Launch the local HTTP development server
python manage.py runserver 8000

Navigate to http://127.0.0.1:8000/ in your browser. You will see Django's default rocket launch greeting page confirming a successful setup!


4. Understanding the manage.py Script

The manage.py file is a thin executable wrapper around django-admin that sets the DJANGO_SETTINGS_MODULE environment variable to point to your project's settings.py.

Common manage.py commands:

  • python manage.py runserver: Launches the development web server.
  • python manage.py makemigrations: Generates new database migration files based on model changes.
  • python manage.py migrate: Executes pending SQL migrations against the database.
  • python manage.py createsuperuser: Creates an administrative user for /admin/.
  • python manage.py startapp <app_name>: Scaffolds a new application module.
  • python manage.py shell: Opens an interactive Python REPL with Django loaded.

Interactive Quiz

Practice Quiz

Question 1
Why is it critical to install Django inside a Python virtual environment?
Question 2
What is the primary difference between django-admin and manage.py?
Question 3
What command runs initial database migrations to configure auth and session tables?
Question 4
What does the command pip freeze > requirements.txt accomplish?
Question 5
Why is python manage.py runserver intended strictly for local development?
Next Lesson

Django Project Structure

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
NoneDjango Project Structure

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext