{"id":2327,"date":"2026-07-24T00:25:02","date_gmt":"2026-07-23T17:25:02","guid":{"rendered":"https:\/\/sumberlaba.com\/index.php\/2026\/07\/24\/how-to-build-a-blog-from-scratch-with-django-a-step-by-step-guide\/"},"modified":"2026-07-24T00:25:03","modified_gmt":"2026-07-23T17:25:03","slug":"how-to-build-a-blog-from-scratch-with-django-a-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/sumberlaba.com\/index.php\/2026\/07\/24\/how-to-build-a-blog-from-scratch-with-django-a-step-by-step-guide\/","title":{"rendered":"How to Build a Blog from Scratch with Django: A Step-by-Step Guide"},"content":{"rendered":"<h1>How to Build a Blog from Scratch with Django: A Step-by-Step Guide<\/h1>\n<p>Django makes building a blog remarkably efficient. This tutorial will guide you through creating a fully functional blog from scratch, covering models, views, templates, and URLs. You\u2019ll have a working blog ready to deploy in minutes.<\/p>\n<p>First, ensure Python and pip are installed. Create a virtual environment, install Django, and start a new project: <code>django-admin startproject myblog<\/code>. Then create a blog app: <code>python manage.py startapp blog<\/code>. Add <code>'blog'<\/code> to <code>INSTALLED_APPS<\/code> in <code>settings.py<\/code>.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/sumberlaba.com\/wp-content\/uploads\/2026\/07\/article-1784827500665.jpg\" alt=\"Article illustration\" style=\"display:block;margin:20px auto;max-width:100%;height:auto;border-radius:8px;\" \/><\/p>\n<h2>1. Define Your Blog Model<\/h2>\n<p>Open <code>blog\/models.py<\/code> and create a <code>Post<\/code> model with fields for title, slug, content, and publication date.<\/p>\n<pre><code>from django.db import models\nfrom django.utils import timezone\n\nclass Post(models.Model):\n    title = models.CharField(max_length=200)\n    slug = models.SlugField(unique=True)\n    content = models.TextField()\n    published_date = models.DateTimeField(default=timezone.now)\n\n    def __str__(self):\n        return self.title\n<\/code><\/pre>\n<p>Run <code>python manage.py makemigrations<\/code> then <code>migrate<\/code> to create the database table.<\/p>\n<h2>2. Create Views and Templates<\/h2>\n<p>In <code>blog\/views.py<\/code>, add a view to list all posts and another to show a single post detail.<\/p>\n<h3>List View<\/h3>\n<pre><code>from django.shortcuts import render, get_object_or_404\nfrom .models import Post\n\ndef post_list(request):\n    posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')\n    return render(request, 'blog\/post_list.html', {'posts': posts})\n<\/code><\/pre>\n<h3>Detail View<\/h3>\n<pre><code>def post_detail(request, slug):\n    post = get_object_or_404(Post, slug=slug)\n    return render(request, 'blog\/post_detail.html', {'post': post})\n<\/code><\/pre>\n<p>Create a <code>blog\/templates\/blog\/<\/code> folder and add <code>post_list.html<\/code> and <code>post_detail.html<\/code> with simple loops and variable output.<\/p>\n<h2>3. Configure URLs<\/h2>\n<p>In <code>blog\/urls.py<\/code>, map the views:<\/p>\n<pre><code>from django.urls import path\nfrom . import views\n\nurlpatterns = [\n    path('', views.post_list, name='post_list'),\n    path('&lt;slug:slug&gt;\/', views.post_detail, name='post_detail'),\n]\n<\/code><\/pre>\n<p>Include the blog URLs in the project\u2019s <code>urls.py<\/code>:<\/p>\n<pre><code>from django.urls import include, path\n\nurlpatterns = [\n    path('', include('blog.urls')),\n]\n<\/code><\/pre>\n<h2>4. Run and Test Your Blog<\/h2>\n<p>Run <code>python manage.py runserver<\/code> and visit <code>http:\/\/127.0.0.1:8000\/<\/code>. You should see your blog. Use the Django admin to add posts (register <code>Post<\/code> in <code>admin.py<\/code> first).<\/p>\n<p>Congratulations! You\u2019ve built a Django blog from scratch. Expand it with categories, comments, or markdown support as you grow.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Build a Blog from Scratch with Django: A Step-by-Step Guide Django makes building a blog remarkably efficient. This tutorial will guide you through creating a fully functional blog from scratch, covering models, views, templates, and URLs. You\u2019ll have a working blog ready to deploy in minutes. First, ensure Python and pip are installed. &hellip; <\/p>\n","protected":false},"author":2716,"featured_media":2326,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2327","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-non-category"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts\/2327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/users\/2716"}],"replies":[{"embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/comments?post=2327"}],"version-history":[{"count":1,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts\/2327\/revisions"}],"predecessor-version":[{"id":2328,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts\/2327\/revisions\/2328"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/media\/2326"}],"wp:attachment":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/media?parent=2327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/categories?post=2327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/tags?post=2327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}