Build Your First Django App, Part 1
It’ll consist of two parts:
- A public site that lets people view polls and vote in them.
- An admin site that lets you add, change, and delete polls.
What This Article Will Cover
- How to verify and install Django
- Creating a Django project and understanding the file structure
- Starting the development server
- Creating your first app: the Polls application
- Writing your first Django view and URLconf
- Adding your app to INSTALLED_APPS
- Testing your basic Django app in the browser
- Next steps: Enhancing the Polls app
Step 1: Create a Django Project Folder:
- Create a folder for your tutorial project:
mkdir polls_project
cd polls_project
Step 2: Create and activate a virtual environment in Python:
On Windows:
python -m venv venv
venv\Scripts\activate
On macOS/Linux:
python3 -m venv venv
source venv/bin/activate
To deactivate the virtual environment (on any OS), simply run:
deactivate
Step 3: Verify and Install Django
- Open your terminal and check if Django is installed:
python -m django --version
- If Django is not installed, follow the Django installation guide.
- Ensure you're using Python 3.10 or later for Django 5.2 or newer.
python -m pip install Django
pip list
Step 4: Create a Django Project
1. Start a new project:
django-admin startproject polls_project
2. Navigate into the project folder
cd polls_project
Project structure created (inside polls_project
manage.py
polls_project/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py
- This is separate from the venv/ folder.
- You typically keep venv/ outside the project directory, like this:
venv/
polls_project/
- manage.py : Command-line utility for your Django project.
- polls_project/ : Contains settings, URLs, WSGI, and ASGI entry points
Step 5: Run the Development Server
Run your server to confirm everything works:
Project Path Tip: To run the server, make sure you're in the same directory as manage.py (usually the project root) and that your virtual environment (venv) is activated.
python manage.py runserver
Visit http://127.0.0.1:8000 in your browser. You should see the Django welcome page.
Step 6: Create the Polls App
Generate your first app:
python manage.py startapp polls
This creates the folder structure for the app.
Your polls directory will now include models, views, admin, and other essential files.
Step 7: Write Your First View
Edit polls/views.py:
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
Step 8: Create URLs for the Polls App
In polls/urls.py (create this file):
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index"),
]
Update polls_project/urls.py to include the polls app:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("polls/", include("polls.urls")),
path("admin/", admin.site.urls),
]
Step 9: Add the App to Installed Apps
Open polls_project/settings.py and add 'polls' to the INSTALLED_APPS list:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls', # 👈 Add this line
]
Visit http://127.0.0.1:8000/polls/ to see your first Django-powered page!
Best Approach/Recommendation
Here are a few key tips to implement what you’ve learned:
- Keep practicing by tweaking your polls app — add questions, forms, or templates.
- Break down the official Django tutorial into digestible steps to avoid overwhelm.
- Don’t skip reading error messages — they're great learning tools.
- Use virtual environments to manage dependencies and keep projects isolated.
Conclusion & What to Do Next
You’ve successfully created your first Django project and built a basic app from scratch. That’s a huge milestone in your web development journey!
📘 First, we’ll enhance this Polls project by adding templates, models, and database integration.
📚 Coming Up Next: We’ll guide you through building a more advanced project—the Local Library Management System, based on the MDN Django Tutorial. This is a great next step to practice database relationships, user authentication, and admin-level control in Django.
Happy coding with Django!