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)
Bash

If not → cd into it (e.g. cd ~/django-learn-2026)

Step 2: The Command to Create an App

Run this:

Bash
  • 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:

text

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):

Python

Add this line at the end:

Python

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:

Bash

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.

  1. Open polls/views.py
Python
  1. Create polls/urls.py (new file! — apps can have their own URL files)
Python
  1. Connect the app’s URLs to the main project.

Open mysite/urls.py (project level)

Change it to:

Python

include(‘polls.urls’) = “delegate everything starting with /polls/ to the polls app’s urls.py”

Step 6: Run & Test!

Bash

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)

  1. “No module named ‘polls'” → Forgot to add to INSTALLED_APPS
  2. 404 when visiting /polls/ → Forgot include(‘polls.urls’) or typo in path
  3. “App not found” → Ran startapp outside project folder (no manage.py)
  4. View not found → Forgot to import in app’s urls.py (from . import views)
  5. 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:

Python

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. 💪🇮🇳

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *