Chapter 7: Django Create App
What is an “App” in Django? (The Most Important Concept)
A Django project is the whole website/container (like your house).
An app is a modular, reusable piece inside it (like a room: kitchen, bedroom, study).
- One project can have many apps (blog app + user app + payments app)
- Apps are pluggable — you can copy an app to another project
- Official tutorial uses a “polls” app → we’ll do the same, but explain deeply
Key rule: Never put models/views/templates directly in the project folder. Always create an app for real features.
Step 1: Make Sure You’re in the Right Place
Terminal should show:
- (venv) activated
- You’re inside your project folder (where manage.py lives)
|
0 1 2 3 4 5 6 7 8 |
# Quick check ls # or dir on Windows # Should show: manage.py mysite/ venv/ |
If not → cd into it (e.g. cd ~/django-learn-2026)
Step 2: The Command to Create an App
Run this:
|
0 1 2 3 4 5 6 |
python manage.py startapp polls |
- python manage.py → uses your project’s settings/environment
- startapp → “please create a new app”
- polls → name of the app (lowercase, no spaces/hyphens usually best; can be blog, todo, shop, etc.)
What happens? A new folder appears:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
polls/ ├── __init__.py # makes it a Python package ├── admin.py # where you'll register models for admin later ├── apps.py # app config (usually leave default) ├── migrations/ # empty folder for database changes │ └── __init__.py ├── models.py # define your database tables here ├── tests.py # write tests here └── views.py # your page logic goes here |
No extra files yet — perfect & clean.
Step 3: Tell Django “Hey, I Have a New App” (Very Important!)
Django won’t know about your app until you add it to INSTALLED_APPS.
Open mysite/settings.py (your project settings)
Find the INSTALLED_APPS list (it’s near the top):
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # ← add your app here ↓ ] |
Add this line at the end:
|
0 1 2 3 4 5 6 7 |
'polls.apps.PollsConfig', # recommended modern way # or just 'polls' (also works, but less explicit) |
Why PollsConfig instead of just ‘polls’?
- It’s the recommended way since Django 1.9+
- Lets you customize app behavior later (e.g. app name for admin, default site)
- Avoids rare naming conflicts
Save the file.
Step 4: Quick Test — Does Django Know About the App?
Run:
|
0 1 2 3 4 5 6 |
python manage.py runserver |
Look at the startup message:
It should not complain about anything new.
Now stop it (Ctrl+C).
Step 5: Hello World Inside the App (Make It Alive!)
Let’s create the simplest possible view in the app.
- Open polls/views.py
|
0 1 2 3 4 5 6 7 8 9 |
from django.http import HttpResponse def index(request): return HttpResponse("Hello, world. You're at the polls index page! 🚀") |
- Create polls/urls.py (new file! — apps can have their own URL files)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 |
from django.urls import path from . import views # . means current app urlpatterns = [ path('', views.index, name='index'), # '' = root of this app ] |
- Connect the app’s URLs to the main project.
Open mysite/urls.py (project level)
Change it to:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 |
from django.contrib import admin from django.urls import path, include # ← add include urlpatterns = [ path('admin/', admin.site.urls), path('polls/', include('polls.urls')), # ← this line! All /polls/... goes to polls app ] |
include(‘polls.urls’) = “delegate everything starting with /polls/ to the polls app’s urls.py”
Step 6: Run & Test!
|
0 1 2 3 4 5 6 |
python manage.py runserver |
Open browser → http://127.0.0.1:8000/polls/
You should see:
Hello, world. You’re at the polls index page! 🚀
🎉 Your first app is working!
Why This Structure Rocks (Quick Recap Table)
| Part | Location | Purpose | Why separate? |
|---|---|---|---|
| Project | mysite/ | Overall config (settings, main urls) | One per website |
| App | polls/ | Features (models, views, templates) | Reusable, organized, multiple possible |
| App URLs | polls/urls.py | App-specific routes | Keeps main urls.py clean |
| Main URLs | mysite/urls.py | Includes app urls | Central traffic director |
Common Mistakes & Fixes (Beginner Traps)
- “No module named ‘polls'” → Forgot to add to INSTALLED_APPS
- 404 when visiting /polls/ → Forgot include(‘polls.urls’) or typo in path
- “App not found” → Ran startapp outside project folder (no manage.py)
- View not found → Forgot to import in app’s urls.py (from . import views)
- Changes not showing → Server auto-reloads, but restart if weird (Ctrl+C then rerun)
Bonus: Make It Prettier (Optional First Upgrade)
Change polls/views.py to use a tiny template later, but for now:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 |
def index(request): return HttpResponse(""" <h1 style="color: #006400; text-align: center; margin: 100px;"> నమస్తే Hyderabad! Your Polls App is Ready! 🌟 </h1> <p style="text-align: center;">Django 6.0.1 • Jan 31, 2026</p> """) |
Refresh → Telugu welcome!
What’s Next? Your Call!
You’ve now:
- Created an app
- Wired it up
- Seen it live
Tell me:
- “Let’s add models & database to polls app”
- “Show me the admin panel for this app”
- “How to create templates properly (HTML files)”
- “Explain the difference between project & app again”
- Or “I got error X — help!” (paste it)
You’re moving fast — super proud of you! Let’s keep building this thing into something cool. 💪🇮🇳
