Django is a powerful Python web framework that helps you build secure, scalable web applications quickly. In this blog, we’ll walk through a complete Django project setup from scratch, using clear commands and best practices.
This guide is perfect if you’re a beginner or setting up a fresh Django project for production or learning.
Prerequisites
Before starting, make sure you have:
Check your Python version:
python --version
Step 1: Create a Project Directory
First, create and move into a new directory for your project.
mkdir django_project
cd django_project
Step 2: Create a Virtual Environment (Recommended)
A virtual environment keeps your project dependencies isolated.
python -m venv venv
Activate it:
On Linux / macOS
source venv/bin/activate
On Windows
venv\Scripts\activate
You should now see (venv) in your terminal.
Step 3: Upgrade pip
Always keep pip updated.
pip install --upgrade pip
Step 4: Install Django
Install the latest stable version of Django.
pip install django
Verify installation:
django-admin --version
Step 5: Create a Django Project
Now create your Django project.
django-admin startproject config .
The dot (.) prevents creating an extra nested folder.
Your structure will look like:
django_project/
├── config/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── asgi.py
│ └── wsgi.py
├── manage.py
└── venv/
Step 6: Run Initial Migrations
Django uses migrations to manage database schema.
python manage.py mimgrate
Step 7: Create a Superuser (Admin)
To access Django admin panel:
python manage.py createsuperuser
Enter:
Username
Email (optional)
Password
Step 8: Run the Development Server
Start the Django server:
python manage.py runserver
Open your browser and visit:
http://127.0.0.1:8000/
Admin panel:
http://127.0.0.1:8000/admin/
Your Django project is now running!
Step 9: Create a Django App
Create an app for your features (e.g., blog, users, core).
python manage.py startapp blog
Project structure now:
blog/
├── admin.py
├── apps.py
├── models.py
├── tests.py
├── views.py
└── migrations/
Step 10: Register App in Settings
Open config/settings.py and add your app:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
]
Step 11: Create Models and Migrate
After writing models in models.py:
python manage.py makemigrations
python manage.py migrate
Step 12: Freeze Dependencies (Best Practice)
Save installed packages:
pip freeze > requirements.txt
Later you can install them using:
pip install -r requirements.txt
Common Django Commands Cheat Sheet
python manage.py runserver
python manage.py startapp app_name
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py shell
Conclusion
Setting up a Django project is straightforward when you follow a structured approach. With virtual environments, clean project structure, and proper commands, you’re ready to build powerful web applications.