Django
The Django MVT Framework
For full documentation visit djangoproject.com.
Over 10 Years | Multiple Projects | Preferred
Django is a high-level Python web framework designed for rapid development, secure data handling, and clean code architecture. It strictly adheres to the Model-View-Template (MVT) design pattern.
- Step 1: Install Django & Start a Project
First, use your terminal to set up a virtual environment and install the core framework.
# Create and activate a virtual environment
python -m venv env
source env/bin/activate # On Windows use: env\Scripts\activate
# Install Django
pip install django
# Initialize a project named "myproject"
django-admin startproject myproject .
- Step 2: Create a Django App
Django organizes features into modular, self-contained sub-applications. Create an application dedicated to displaying items.
python manage.py startapp items
Register this new app inside your myproject/settings.py file:
INSTALLED_APPS = [
# ... default django apps
'items',
]
- Step 3: Define the Model (Data Layer)
Models manage database layouts implicitly using Python classes. Open items/models.py to create a basic table schema:
from django.db import models
class Item(models.Model):
name = models.CharField(max_length=100)
description = models.TextField()
def __str__(self):
return self.name
Run migrations to generate the matching database table structures:
python manage.py makemigrations
python manage.py migrate
- Step 4: Write the View (Logic Layer)
Views fetch data requested by the client and forward it downstream. Open items/views.py:
from django.shortcuts import render
from .models import Item
def item_list(request):
# Fetch all records out of the database
all_items = Item.objects.all()
# Send data directly into the user template
return render(request, 'items/list.html', {'items': all_items})
- Step 5: Design the Template (Presentation Layer)
Templates display content dynamically using standard HTML files combined with Django variables. Create a new template file at items/templates/items/list.html:
<!DOCTYPE html>
<html>
<head>
<title>Item Inventory</title>
</head>
<body>
<h1>Available Items</h1>
<ul>
{% for item in items %}
<li><strong>{{ item.name }}</strong>: {{ item.description }}</li>
{% empty %}
<li>No items found in the database.</li>
{% endfor %}
</ul>
</body>
</html>
- Step 6: Route Your URLs (Routing Layer)
Map user web requests straight to the custom view function using specific URL patterns.Create an internal routing file named items/urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.item_list, name='item_list'),
]
Next, include those modular paths in the core project routing file found at myproject/urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('items/', include('items.urls')), # Includes sub-app routes
]
- Step 7: Launch the Server
Start the local developer environment to view your functional database application:
python manage.py runserver
Open your internet browser and navigate to http://localhost:8000 to see your running instance.
So easy, AI does do it!
Normally, doing all this by hand is just as fast for me. But I like to let my AI have at it from time to time.
There are no special commands as in other PHP based frameworks, but projects are still very quick to build out and customize. This has become my preferred way of setting up general web systems these days.
Development Frameworks
JS Frameworks
CSS Frameworks
More Frameworks
Social Media
---
title: Django
text: The Django MVT Framework
image: /assets/svg/django1.svg
link:
target:
---