Hello, today marks my 4th day in my journey of developers. Am quite excited to share what I did today while learning Django structure.
step 1; setting up my project.
As part of my tech journey, I decided to build a Django project to practice web development. I named my project njeriproject. Here’s how I got started:
django-admin startproject njeriproject
cd njeriproject
python -m venv rbenv
rbenv\Scripts\activate
pip install django
in this i created a virtual environment by the name brenv and installed django.
Then I created two apps inside it:
Step 2: Understanding the Django Structure
After running the command, my project looked like this:
njeri/
├── manage.py
├── mysite/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── asgi.py
│ └── wsgi.py
I explored and learned what each file does:
manage.py- This lets me run commands like runserver or makemigrations
settings.py- This Contains all project settings like installed apps and database config
urls.py- Handles all routing and linking to app URLs
asgi.py and wsgi.py- Help when deploying to a web server
Step 3: Creating Two Django Apps
To organize my site into separate features, I created two apps where each app came with important files like;
views.py, models.py, admin.py, apps.py, tests.py, and a migrations/ folder
Step 4: Registering the Apps
To make Django recognize both apps, I opened mysite/settings.py and added them in INSTALLED_APPS
Step 5: Writing Views and Creating URLs
For app1
In app1/views.py i created this code
from django.shortcuts import render
def app1_home(request):
return render(request, 'app1_home.html')
then created urls.py for app1 added the following in it
from django.urls import path
from .views import app1_home
urlpatterns = [
path('', app1_home, name='app1_home'),
]
** For app2**
In app2/views.py:
from django.shortcuts import render
def app2_home(request):
return render(request, 'app2_home.html')
Then I created app2/urls.py:
from django.urls import path
from .views import app2_home
urlpatterns = [
path('', app2_home, name='app2_home'),
]
Step 6: Connecting Both Apps in mysite/urls.py
Now it was time to connect both apps to the main URL configuration.
In mysite/urls.py I wrote:
from django.contrib import admin
from django.urls import path, include
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('app1/', include('app1.urls')),
path('app2/', include('app2.urls')),
]
At first, I forgot to import include and Django gave me an error. But once I fixed that, the server ran smoothly.
Step 7: Adding Templates for HTML Pages
After getting simple text responses to show up using HttpResponse, I wanted to display proper HTML pages using templates.
So I created a templates folder inside each app
In both app1 and app2, I made this folder structure:
app1/
└── templates/
└── app1/
└── home.html
app2/
└── templates/
└── app2/
└── home.html
I created basic HTML files in both apps.
I updated the views to render templates
In app1/views.py:
from django.shortcuts import render
def home(request):
return render(request, 'app1/home.html')
In app2/views.py:
`from django.shortcuts import render
def home(request):
return render(request, 'app2/home.html')
Step 8: Testing It All
I ran the server with the following command
python manage.py runserver
Then I opened my browser and tested. this is what my page looked like after adding /app1 in the URL generated.
Seeing both apps work made me feel proud and confident in using Django.
This is what I Learned
- Django projects can be modular — I can add many apps like I did with app1 and app2.
- The outer folder (njeri) holds everything; the inner mysite/ config folder manages settings, URLs, and deployment files.
- Even small mistakes (like forgetting include) can break the app — but the error messages help a lot
Finally
Building the njeri project taught me how Django is structured and how everything connects from creating apps, to writing views, to linking URLs. Working with two apps in one project showed me Django’s power and flexibility.
I’m still learning, but now I feel more confident to build real Django websites.
Feel free to connect and grow together at github @Rebecca-254
Top comments (0)