Getting Started with Django
Date Published

Django is a powerful Python framework for building secure and scalable web applications.
This guide will walk you through setting up your development environment and creating your first Django project from scratch.
✅ Prerequisites
Before you begin, make sure you have:
- Python 3.8 or higher installed
- pip, the Python package manager
- A terminal or command prompt
- Basic understanding of Python (functions, classes, etc.)
You can verify your Python version with:
1python --version
⚙️ Step 1: Set Up a Virtual Environment
A virtual environment keeps your project’s dependencies isolated from other Python projects.
1.Create a virtual environment:
1python -m venv myenv
2.Activate the environment
On Windows:
1myenv\Scripts\activate
On macOS / Linux:
1source myenv/bin/activate
💡 When activated, you’ll see
(myenv)at the beginning of your terminal line.
📦 Step 2: Install Django
Once your environment is active, install Django using pip:
1pip install django
Check your Django version:
1django-admin --version
💡 Tip: Always keep a
pip freeze > requirements.txtrequirements.txtfile to record dependencies:
🏗️ Step 3: Create a New Django Project
Now create your first Django project:
1django-admin startproject myproject2cd myproject
This command generates the basic Django project structure, including configuration files and the built-in development server.
🧩 Step 4: Create a New App
Django projects are made up of smaller applications.
Let’s create one called myapp:
1python manage.py startapp myapp
Next, register your new app in myproject/settings.py:
1INSTALLED_APPS = [2 'django.contrib.admin',3 'django.contrib.auth',4 'django.contrib.contenttypes',5 'django.contrib.sessions',6 'django.contrib.messages',7 'django.contrib.staticfiles',8 'myapp', # 👈 Add this line9]
🧱 Step 5: Initial Setup
1. Create database tables
1python manage.py migrate
This applies Django’s default migrations and sets up the database tables.
2. Create a superuser (admin)
1python manage.py createsuperuser
Follow the prompts to create an admin user with a username, email, and password.
🚀 Step 6: Run the Development Server
Start the built-in Django server:
1python manage.py runserver
Then open your browser and visit:
You’ll see Django’s welcome page!
To access the admin interface, go to:
👉 http://127.0.0.1:8000/admin/
🗂️ Project Structure Overview
After these steps, your directory should look like this:
1myproject/2├── manage.py3├── myproject/4│ ├── __init__.py5│ ├── asgi.py6│ ├── settings.py7│ ├── urls.py8│ └── wsgi.py9└── myapp/10 ├── __init__.py11 ├── admin.py12 ├── apps.py13 ├── models.py14 ├── tests.py15 └── views.py
🧭 Step 7: Add a Simple View and URL
Let’s display a simple message in your browser.
Open myapp/views.py and add:
1from django.http import HttpResponse23def home(request):4 return HttpResponse("Hello, Django!")5
Then create myapp/urls.py (if it doesn’t exist):
1from django.urls import path2from . import views34urlpatterns = [5 path('', views.home, name='home'),6]7
Finally, connect your app’s URLs to the main project in myproject/urls.py:
1from django.contrib import admin2from django.urls import path, include34urlpatterns = [5 path('admin/', admin.site.urls),6 path('', include('myapp.urls')), # 👈 Add this line7]8
Now, reload http://127.0.0.1:8000/
and you should see "Hello, Django!" 🎉
🧩 Next Steps
From here, you can start expanding your app:
- 🗃️ Define models in
models.py - 🧠 Build views in
views.py - 🌐 Set up routes in
urls.py - 🖼️ Create HTML templates in a
templates/folder - 🎨 Add static files (CSS, JS, images) in a
static/folder
💡 Best Practices
1. Always activate your virtual environment before working:
1source myenv/bin/activate
2. Keep your dependency list up to date:
1pip freeze > requirements.txt2
3. Add a .gitignore file to exclude temporary files and virtual environments.
4. Use Git (or another version control system) to track your project changes.
📚 Learn More
If you want to explore Django in depth, the official documentation is the best place to continue learning. It covers everything from models and templates to deployment and security best practices:
👉 Official Django Documentation: https://docs.djangoproject.com/
Other Useful Resources:
- MDN Django Server-side Guide: https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/Django
- awesome-django repo: https://github.com/wsvincent/awesome-django
