Lesson 3: Django Apps
📘 Lesson 3: Django Apps
🔰 Introduction
In Django, a project is the whole website — but the real power comes from apps.
Each feature inside a Django project is built as a separate app so your project stays clean, organized, and professional just like modern company websites.
Examples of apps:
blogaccounts(login system)storeapipoems(for your future poetry system)
By the end of this lesson, you will:
✔ Understand what an app is
✔ Create your first Django app
✔ Install the app inside settings.py
✔ Build the foundation for your project’s future apps
✔ Be ready for the homework: create a blog app
🧩 1. What is a Django App?
A Django app is:
- A module inside your project
- Responsible for doing one job
- Reusable (you can copy it into another project)
- Easy to maintain
Think of a Django project like a company building:
| Floor | Purpose |
|---|---|
| Project | Entire building |
| App | A department (HR, IT, Finance) |
Each department does one job.
Each app does one job.
🏗 2. Creating New App
Make sure your virtual environment is active:
source venv/bin/activate
Go inside your Django project directory (where manage.py is):
cd hello_django
Create your new app:
python manage.py startapp home
You will now see this new folder:
home/
admin.py
apps.py
models.py
views.py
urls.py (you will create this)
This app is now part of your project — but Django does not use it yet.
You must install it.
⚙️ 3. Installing the App in settings.py
Open:
hello_django/config/settings.py
Find the INSTALLED_APPS section.
Add your app:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'core',
'home', # Your apps
]
That’s it — your app is now registered!
🌐 4. Creating the New App View
Inside home/views.py:
from django.http import HttpResponse
def homepage(request):
return HttpResponse("Welcome to my first Django app!")
Now create a urls.py file inside the app:
home/urls.py
Add this:
from django.urls import path
from . import views
urlpatterns = [
path('', views.homepage, name='homepage'),
]
🔗 5. Include App URLs in Project URLs
Open:
hello_django/config/urls.py
Update to:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('core/', include('core.urls')),
path('', include('home.urls')),
]
Now visit:
run the server:
python manage.py runserver 0.0.0.0:8011
then visit:
http://your-server-ip:8011/
You should see:
“Welcome to my first Django app!”
🚨 Beginners Troubleshooting
❗ “ModuleNotFoundError: No module named ‘home’”
You created the app outside the project folder.
Make sure home/ is next to manage.py.
❗ “TemplateDoesNotExist”
You added templates before creating the templates folder.
We will fix this in Lesson 6.
❗ Running server on busy port
Use a different port:
python manage.py runserver 0.0.0.0:8011
(We use 8011 in all lessons to avoid conflicts)
📝 Homework
Create a new app called blog
Your task:
- Create the app
python manage.py startapp blog - Add it to
INSTALLED_APPS - Create a view:
Insideblog/views.pydef blog_home(request): return HttpResponse("This is the blog homepage.") - Create
urls.pyfor the app - Include it in project
urls.pyat:/blog/
Example:
http://your-server-ip:8011/blog/
It should display:
This is the blog homepage.