Blog with Django
A complete blog with posts, categories, comments and an admin panel, built the Django way.
What you'll learn
- βModels, views, templates and URLs
- βThe Django admin
- βBuilt-in authentication and forms
What you'll build
- βPost list with pagination and categories
- βPost detail with comments
- βLogin to write and edit your posts
- βAdmin panel for moderation
Step-by-step guide
- 1
Start the project
python -m venv venv; pip install django; django-admin startproject mysite; python manage.py startapp blog.
- 2
Models
Category(name, slug) and Post(title, slug, author FK User, category FK, body, published_at, status) and Comment(post FK, name, text, approved).
- 3
Admin
Register models with list_display, search_fields and prepopulated_fields = {"slug": ("title",)}; create a superuser.
- 4
Views and URLs
ListView with paginate_by = 10 and DetailView looked up by slug; wire them in blog/urls.py.
- 5
Templates
A base.html with blocks; extend it for list and detail; use {% url %} for links.
- 6
Comments form
A ModelForm; save comments as not approved until a moderator approves them in the admin.
- 7
Auth for authors
Use django.contrib.auth views for login; LoginRequiredMixin on Create/UpdateView; check request.user == post.author.
- 8
Go live
Switch to PostgreSQL, set DEBUG = False, ALLOWED_HOSTS, collectstatic, and run with gunicorn.
π Make it stand out
- +Tags with django-taggit
- +RSS feed and sitemap (built into Django)
- +Search with PostgreSQL full-text search