So far, we have learned the fundamental concepts of Django such as Models, Views, Templates, Forms and CRUD operations.
Now it is time to build a complete real-world application by applying all these concepts together.
| Module | Description |
|---|---|
| Authentication | Admin Login & Logout |
| Category | Manage Blog Categories |
| Posts | Create, Edit and Delete Blog Posts with Image |
| Comments | User Comments |
| Search | Search Blog Posts |
| Pagination | Display Posts Page Wise |
We will create a new Django Project inside a Virtual Environment.
This keeps the project independent and manages all required packages in one place.
mkdir blogproject
cd blogproject
python -m venv venv
venv\Scripts\activate
pip install django
django-admin startproject blogproject
pip install mysqlclient
pip install pillow
pip install django-ckeditor
code .
python manage.py runserver
| Package | Purpose |
|---|---|
| Django | Python Web Framework |
| mysqlclient | Connect Django with MySQL Database |
| Pillow | Support Image Upload in Blog Posts |
| django-ckeditor | Rich Text Editor for Blog Content |
By default, Django uses SQLite. For this project, we will use MySQL as our database.
CREATE DATABASE BlogDB;
blogproject/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'BlogDB',
'USER': 'root',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '3306',
}
}
python manage.py migrate
A Django Project can contain multiple Applications.
We will create a separate application named blog to manage all blog-related features.
python manage.py startapp blog
Open:
blogproject/settings.py
Add the app name inside INSTALLED_APPS.
'blog',
Django follows a modular architecture where each application is responsible for a specific feature.
The blog app will contain all files related to the Blog Module such as Models, Views, Forms and Templates.
blogproject
│
├── blog
│ ├── models.py
│ ├── views.py
│ ├── forms.py
│ ├── admin.py
│ └── migrations
│
├── blogproject
│
├── manage.py
│
└── venv
Before developing the Blog Project, we will configure the Templates, Static Files and Media Files.
This prepares the project for storing HTML pages, CSS, JavaScript and uploaded Blog Images.
blogproject
│
├── blog
│
├── templates
│
├── static
│ ├── css
│ ├── js
│ └── images
│
├── media
│
├── manage.py
│
└── blogproject
Open blogproject/settings.py and update the TEMPLATES setting.
'DIRS': [BASE_DIR / 'templates'],
Add the following code in settings.py.
STATIC_URL = 'static/'
STATICFILES_DIRS = [
BASE_DIR / 'static',
]
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
Open blogproject/urls.py.
Import the following modules.
from django.conf import settings
from django.conf.urls.static import static
Add the following code after urlpatterns.
if settings.DEBUG:
urlpatterns += static(
settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT
)
| Static Files | Media Files |
|---|---|
| CSS | Uploaded Images |
| JavaScript | User Uploaded Files |
| Website Logo | Blog Featured Images |
Instead of creating the layout for every page separately, we will create a common base.html file.
This file contains the common Header, Navigation Bar and Footer used throughout the project.
templates/base.html
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1">
<title>Django Blog Portal</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css"
rel="stylesheet">
<!-- Font Awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">
<!-- Custom CSS -->
<link rel="stylesheet"
href="{% static 'css/style.css' %}">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand"
href="/">
<i class="fa-solid fa-blog"></i>
Django Blog
</a>
<button class="navbar-toggler"
data-bs-toggle="collapse"
data-bs-target="#menu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse"
id="menu">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link"
href="/">
<i class="fa-solid fa-house"></i>
Home
</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="#">
<i class="fa-solid fa-folder"></i>
Categories
</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="#">
<i class="fa-solid fa-file-lines"></i>
Posts
</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="#">
<i class="fa-solid fa-right-to-bracket"></i>
Login
</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container my-5">
{% block content %}
{% endblock %}
</div>
<footer class="bg-dark text-white text-center py-3">
<p class="mb-0">
© 2026 Django Blog Portal |
Developed During Python Django Training
</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Finally, we will connect the Blog App with the main project and display the Home page.
blog/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'),
]
from django.shortcuts import render
def home(request):
return render(request,'home.html')
Open blogproject/urls.py.
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls')),
]
templates/home.html
{% extends 'base.html' %}
{% block content %}
<div class="text-center mt-5">
<h1>Welcome To Django Blog Portal</h1>
<p>
Our Blog Project setup is completed successfully.
</p>
</div>
{% endblock %}
python manage.py runserver
python -m venv venv
pip install django
django-admin startproject blogproject
python manage.py startapp blog
python manage.py migrate
python manage.py runserver
Create a new Django project named News Portal by following the same steps demonstrated in today's Blog Project.