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.
1# 1. Create a dedicated virtual environment
2python -m venv venv
3
4# 2. Activate virtual environment
5# On macOS / Linux:
6source venv/bin/activate
7
8# On Windows (PowerShell):
9.\venv\Scripts\Activate.ps1
10# On Windows (CMD):
11.\venv\Scripts\activate.bat
Verify that the active python binary points inside your virtual environment:
1which python # or 'Get-Command python' on Windows
2. Installing Django and Freezing Dependencies
1# Upgrade pip package installer
2python -m pip install--upgrade pip
3
4# Install latest production Django release
5pip install django
6
7# Verify Django installation and version
8python -m django --version
9
10# Freeze active dependencies into requirements.txt
11pip 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.
1# Initialize a new Django project named 'config' inside the current directory
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• Knowledge Check
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.