As a beginner learning Django, I wanted to go beyond the usual single-app setup and try something more practical: a Django project with two apps, where each app has its own templates.
This post walks you through exactly how I set it up — with actual code and screenshots from my own project. If you’re getting started or want to organize your project more cleanly, this guide is for you.
Folder Structure
Here’s what the structure looks like in my project:
web_project/
│
├── hello/
│ ├── templates/
│ │ └── hello/
│ │ ├── sample.html
│ │ └── sample.css
│ ├── views.py
│ ├── urls.py
│
├── users/
│ ├── templates/
│ │ └── users/
│ │ └── register.html
│ ├── views.py
│ ├── urls.py
│
├── web_project/
│ └── settings.py
│ └── urls.py
└── manage.py
✅ Step-by-Step Setup
Step 0: Create & Activate a Virtual Environment
Before working on your Django project, it's best to set up a virtual environment so your project dependencies are isolated from your system Python.
🌀 1. Create the Virtual Environment
python -m venv venv
This will create a folder named venv/
in your project directory.
⚡ 2. Activate the Virtual Environment
Now, depending on your operating system, run one of the following:
✅ On Windows:
venv\Scripts\activate
✅ On Linux/macOS:
source venv/bin/activate
🧪 3. Confirm It’s Activated
Once activated, you’ll see the environment name (like (venv)
) in your terminal prompt.
Then you can install Django safely inside the environment:
pip install django
1. Create the Project and Apps
django-admin startproject web_project
cd web_project
python manage.py startapp hello
python manage.py startapp users
2. Register Apps in settings.py
INSTALLED_APPS = [
...
'hello',
'users',
]
3. Write Your Views
hello/views.py
from django.shortcuts import render
def hello(request):
return render(request, 'hello/sample.html')
4. Create Templates
📄 hello/templates/hello/sample.html
<!DOCTYPE html>
<html>
<head>
<title>About django</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a sample Django web project.</p>
<p>Welcome to the Hello World page!</p>
</body>
</html>
#### 📄 `users/templates/users/register.html`
html
This is the user registration page
5. Set Up URL Routing
hello/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.hello, name='hello'),
]
users/urls.py
from django.urls import path
from . import views
def register(request):
return render(request, 'users/register.html')
urlpatterns = [
path('', register, name='register'),
]
web_project/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('hello/', include('hello.urls')),
path('users/', include('users.urls')),
]
6. Run the Server
python manage.py runserver
Now open your browser and visit:
- http://127.0.0.1:8000/hello/ → You’ll see the "Hello, World!" template
- http://127.0.0.1:8000/users/ → You’ll see the user register page
🧠 Key Takeaways
- Each app can and should have its own
templates/
folder for better organization. - Always remember to include each app’s URL configuration inside the main project
urls.py
. - Restart the dev server when you make changes to settings or URL configurations.
Top comments (0)