How to Build a Website with Django: A Complete Guide
Published on December 09, 2025
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. In this article, we’ll build a fully functional blog website step by step.
1. Setting Up Your Development Environment
Before we start, ensure you have Python 3.12+ installed, pip, and a code editor like VS Code or PyCharm.
Step 1.1: Create a virtual environment
# Create a project folder
mkdir django_blog_project
cd django_blog_project
# Create a virtual environment
python -m venv venv
# Activate the environment
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate
Step 1.2: Install Django
pip install django
# Check installation
django-admin --version
2. Creating the Django Project
django-admin startproject mysite .
Run the server:
python manage.py runserver
Visit http://127.0.0.1:8000 to see the Django welcome page.
3. Creating a Django App
python manage.py startapp blog
Add 'blog' to INSTALLED_APPS in mysite/settings.py:
INSTALLED_APPS = [
...
'blog',
]
4. Creating the Blog Model
from django.db import models
from django.urls import reverse
from django.utils.text import slugify
class BlogPost(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(max_length=200, unique=True, blank=True)
content = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ['-created_at']
def __str__(self):
return self.title
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super().save(*args, **kwargs)
def get_absolute_url(self):
return reverse('blog_detail', kwargs={'slug': self.slug})
5. Admin Interface
from django.contrib import admin
from .models import BlogPost
@admin.register(BlogPost)
class BlogPostAdmin(admin.ModelAdmin):
list_display = ('title', 'created_at', 'updated_at')
prepopulated_fields = {'slug': ('title',)}
Create superuser:
python manage.py createsuperuser
6. Creating Views and URLs
from django.shortcuts import render, get_object_or_404
from .models import BlogPost
def blog_list(request):
posts = BlogPost.objects.all()
return render(request, 'blog/blog_list.html', {'posts': posts})
def blog_detail(request, slug):
post = get_object_or_404(BlogPost, slug=slug)
return render(request, 'blog/blog_detail.html', {'post': post})
7. Templates
blog_list.html:
{% raw %}
{% extends 'base.html' %}
{% block content %}
Blog Posts
{% for post in posts %}
- {{ post.title }} ({{ post.created_at|date:"F d, Y" }})
{% empty %}
- No posts yet.
{% endfor %}
{% endblock %}
{% endraw %}
blog_detail.html:
{% raw %}
{% extends 'base.html' %}
{% block content %}
{{ post.title }}
Published on {{ post.created_at|date:"F d, Y" }}
{{ post.content|safe|linebreaks }}
← Back to Blog List
{% endblock %}
{% endraw %}
8. Base Template
{% raw %}{% block title %}My Django Blog{% endblock %}{% endraw %}
{% raw %}{% block content %}{% endblock %}{% endraw %}
9. Running the Website
Start the server:
python manage.py runserver
Visit:
10. Optional Enhancements
- Add user authentication to allow posting by users
- Add pagination for blog lists
- Add comments system using Django forms
- Style the blog with Bootstrap 5 or TailwindCSS
- Add SEO meta tags for better search results
This tutorial provides a fully working Django blog website that you can extend into a portfolio, company site, or even an e-commerce platform.