Hi, so today I focused on understanding and applying Django’s MVT architecture, the foundation of how Django apps work.
MODEL – Data layer.
So what is a Model in Django?
I understood Model as a Python class used to define the structure of your database.
Django uses it to create tables automatically, based on your field definitions.
It handles all data-related operations: Create, Read, Update, Delete (CRUD). For example in my previous project I added this kind of model.
from django.db import models
class Item(models.Model):
name = models.CharField(max_length=100)
description = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.name
VIEW – Logic Layer
what is a View in Django?
A View is a Python function (or class) that handles the logic behind a page.
It receives a request, fetches data (usually from the Model), and returns a response (usually a rendered Template).
I created a view to fetch data from the database and send them to the template:
from django.shortcuts import render
def home(request):
return render(request, 'app1/home.html')
TEMPLATE – Presentation Layer
So what is a Template in Django?
A Template is an HTML file used to display content to the user.
It uses Django’s built-in Template Language (DTL) to display variables, loop through data, and include logic.
So in both apps I used the the templates as in the previous article.
URL – Routing Layer
what are URLs in Django?
The URL configuration connects user requests (like http://localhost/products) to the correct view.
URLs act like a bridge between the browser and the backend logic.
Then I used my URLs in my previous article.
HOW IT ALL CONNECTS (MVT FLOW):
- User types http://localhost:8000/products/ URL routes it to view
- View calls the Product model View
- Model fetches data from the database Model
- View passes data to the template View
- Template displays data in HTML Template
Summary of Each Part
Part Django File Purpose
Model- models.py Defines structure of database tables
View- views.py Contains logic to fetch/process data
Template templates/.html Displays data using HTML & DTL
URL- urls.py Connects browser requests to views
My Reflection on Day 5
Understanding how each MVT part plays its role helped me finally see Django as a full web framework — not just scattered files. Now I can create real, working web pages powered by Python and databases, not just static HTML.
Top comments (0)