DEV Community

VALENTINE ACHIENG
VALENTINE ACHIENG

Posted on

## πŸš€ Getting Started with Django: A Two-App Project with Individual Templates

πŸš€ 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: Set Up a Virtual Environment

Before we even touch Django, let's set up a clean Python environment for the project.

  1. Create a virtual environment (you can name it venv or anything):
python -m venv venv
Enter fullscreen mode Exit fullscreen mode
  1. Activate it:
  • On Windows:
  venv\Scripts\activate
Enter fullscreen mode Exit fullscreen mode
  • On Linux/macOS:
  source venv/bin/activate
Enter fullscreen mode Exit fullscreen mode
  1. Install Django:
pip install django
Enter fullscreen mode Exit fullscreen mode

Once Django is installed inside your virtual environment, you’re ready to create your Django project!

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

πŸ“Έ Here’s how my code looks in VS Code:

Image description

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

πŸ“Έ Here’s my actual file in action:

sample html


πŸ“„ users/templates/users/register.html

<h2>This is the user registration page</h2>
Enter fullscreen mode Exit fullscreen mode

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.

πŸ’¬ Final Thoughts

Setting this up helped me understand Django’s project structure and how templates work. It also taught me how to keep things clean when scaling to multiple apps.

Let me know in the comments if you're trying something similar or hit a wallβ€”I’ll be happy to help out!


Would you like this in Markdown format or as a PDF export ready for Dev.to upload?

By: Vall Achieng


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


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

πŸ“Έ Here’s how my code looks in VS Code:

hello view


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

πŸ“Έ Here’s my actual file in action:

sample html


πŸ“„ users/templates/users/register.html

<h2>This is the user registration page</h2>
Enter fullscreen mode Exit fullscreen mode

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.

πŸ’¬ Final Thoughts

Setting this up helped me understand Django’s project structure and how templates work. It also taught me how to keep things clean when scaling to multiple apps.

Let me know in the comments if you're trying something similar or hit a wallβ€”I’ll be happy to help out!

Top comments (0)