DEV Community

Cover image for Getting Started with Django: A Two-App Project with Individual Templates
VALENTINE ACHIENG
VALENTINE ACHIENG

Posted on

Getting Started with Django: A Two-App Project with Individual Templates

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
Enter fullscreen mode Exit fullscreen mode

✅ 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

✅ On Linux/macOS:

source venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

🧪 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
Enter fullscreen mode Exit fullscreen mode

1. Create the Project and Apps

django-admin startproject web_project
cd web_project
python manage.py startapp hello
python manage.py startapp users
Enter fullscreen mode Exit fullscreen mode

2. Register Apps in settings.py

INSTALLED_APPS = [
    ...
    'hello',
    'users',
]
Enter fullscreen mode Exit fullscreen mode

3. Write Your Views

hello/views.py

from django.shortcuts import render

def hello(request):
    return render(request, 'hello/sample.html')
Enter fullscreen mode Exit fullscreen mode

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`

Enter fullscreen mode Exit fullscreen mode


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'),
]
Enter fullscreen mode Exit fullscreen mode

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'),
]
Enter fullscreen mode Exit fullscreen mode

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')),
]
Enter fullscreen mode Exit fullscreen mode

6. Run the Server

python manage.py runserver
Enter fullscreen mode Exit fullscreen mode

Now open your browser and visit:


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