First Django Project
- Learn how to create and run your first Django project step-by-step.
Why This Lesson Is Important?
This is the first hands-on step in Django.
After this lesson, students will:Create a Django project
Understand Django file structure
Run the development server
See Django working in the browser
This builds confidence and removes fear of Django.
1. Creating First Django Project
What is a Django Project?
A Django Project:
Is the main container
Holds settings, URLs, and configurations
Can contain multiple Django apps
👉 One project = One website
Steps Before Creating Project
Activate virtual environment
Django must be installed
Code Example: Create Django Project
Creating a Django Project
Generates default Django project structure
django-admin startproject myproject
Project Folder Structure
myproject/
│
├── manage.py
├── myproject/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── asgi.py
│ └── wsgi.py
Explanation of Files
Alternative (Recommended) Project Creation
Project Creation in Current Folder
Avoids nested folder confusion
django-admin startproject myproject .
2. Running Django Development Server
What is Development Server?
Django provides a built-in lightweight server used only for:
Development
Testing
Learning
❌ Not used in production
Code Example: Run Django Server
Starting Django Development Server
Starts Django local server
python manage.py runserver
Output in Browser
Open browser and visit:
http://127.0.0.1:8000/
You will see:
🎉 The install worked successfully! Congratulations!
What Happens Internally?
Django loads settings
Starts local server
Listens on port 8000
Responds to HTTP requests
3. Changing Server Port (Optional but Useful)
Why Change Port?
Multiple servers running
Avoid port conflict
Code Example: Run Server on Custom Port
Custom Port Server
Runs server on port 8080
python manage.py runserver 8080
4. Common Beginner Errors & Solutions
5. Quick Test: Modify Home Page Message
Why This Test?
Shows Django is fully working
Code Example: Test Django Response [views.py]
Test Django Setup
Returns simple HTTP response
from django.http import HttpResponse
def home(request):
return HttpResponse("My First Django Project")
urls.py
from django.urls import path
from .views import home
urlpatterns = [
path("", home),
]