Django 3 Tutorial: Build a Blogging App

This post will explain how Django 3 works and we’ll create a blogging app in the process. I assume that you already have installed Python 3, Python Virtualenv, and latest version of Django and pillow package as well.

Related Post: How to install Django 3 on Ubutnu

In case you have not installed yet. I have got tutorial video and blog post to help you install Python 3, pip, virtualenv, django 3 and pillow as well.

Related Post: How to install Django 3 on Windows 10

Once you have installed Python 3, pip, virtualenv, and django 3, you can install pillow with the following commads.

pip install pillow

That was about Django 3 Development Environment setup. Let’s create the django project and then django app.

Check Django Version

There are few ways you can check Django version on version irrespective of your operating system. Using command prompt or terminal run the following command. Make sure your Python virtualenv is activated.

django-admin --version

If you are in python shell or python file, you can check django version with the following code

import django

You can list all the python packages installed with their current versions with following command

pip list

Create Django 3 Project

django-admin startproject blogdemo && cd blogdemo

This is how to create a django 3 project and change the directory to project root directory.

Run the Django 3 Server

As soon as you run the Django 3 server, the django project create one folder (__pycache__) and a file (db.sqlite3) in the project.

And you also see a warning about unapplied migrations. This error message is showing because Django ships with builtin admin model.

Here is how to run the and run the django migration

python runserver

Django makemigrations & migrate

makemigrations command is run to create the models for the specific app and migrate is run to apply the models to the database; in other words – migrate is to create the tables structure on the database.

Now kill the running django server with CTRL + C and run the following command to apply the admin models.

python migrate

Let’s Create Django 3 Super User

Run the following command to create django super user and create a user name, password and add your email address to the super user account.

python createsuperuser

After creating django super user, you can login to django admin page with created username and password.


Let’s create Django 3 App

Difference between Django Project and Django App

Django Project: hold only configuration files and folder.

Django App: is like a module that is plug-able to the Django Project.

To create Django Project, run the following command.

python startapp blog

Let’s plug this app to Django Project

Open the under blogdemo/blogdemo folder, now look for INSTALLED_APP list

Create blog app models

We are going to create 3 models in blog/

from django.db import models

class Author(models.Model):
	name = models.CharField(max_length=50)
	bio = models.TextField()

	def __str__(self):

class Category(models.Model):
	category = models.CharField( max_length=50)		
	description = models.TextField()

	def __str__(self):
		return self.category

class Article(models.Model):
	title = models.CharField(max_length=50)
	image = models.ImageField(upload_to="images/")
	content = models.TextField()
	category = models.ForeignKey(Category, on_delete=models.CASCADE)
	author = models.ForeignKey(Author, on_delete=models.CASCADE)

	def __str__(self):
		return self.title

Run migration for blog models

python makemigrations blog


python migrate

Register blog models in blog/

First we need to import all the models in blog/ file and register them to admin page

from django.contrib import admin
# from .models import *
from .models import Author, Category, Article

Let’s configure django project to handle static files/views

Let’s first create templates folder in project root directory and create two html file index.html and single.html

mkdir templates && cd templates && touch {index,single}.html

Open blogdemo/ add templates folder to TEMPLATES list

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
#this DIRS dict value
        'DIRS': [os.path.join(BASE_DIR, 'templates')],

        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [

Django Media Root & URL for images

Add the following code to blogdemo/ This will create media folder in the root directory.

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

The following code will automate the image url creation process and image upload. blogdemo/

from django.conf import settings #added
from django.conf.urls.static import static #added
from django.contrib import admin
from django.urls import path

urlpatterns = [
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) #added

Login to Django Admin page

Run the Django server and login to Django admin page

Create an Author, a Category and a few Articles

I assume that you already have created at-least an Author, a Category, and a few Articles.

Lets Create Blog Views/Controllers

Django’s Views are like controllers in other MVC frameworks like Rails . Views need to have access to the models. We’ll import the blog models and use Django ORM to fetch data from database tables.

from django.shortcuts import render
from .models import Article

def index(request):
	articles = Article.objects.all()
	return render(request, 'index.html', {"articles": articles})

def single(request, id):
	single = Article.objects.get(id=id)
	return render(request, 'single.html', {"single": single})

Let’s Create Blog urls/routes

We’ll have to create file in our /blog app and create routes/urls by importing path module in blog/

from project root directory run the following command or create file manually.

touch blog/

To create url path in blog/ we need to import blog/

from django.urls import path
from . import views

urlpatterns = [
	path('', views.index, name='index'),
	path('<int:id>/', views.single, name='single'),


Add blog urls to project urls

To add blog/ to blogdemo/, we need to import include module.

from django.conf import settings 
from django.conf.urls.static import static 
from django.contrib import admin
from django.urls import path, include # imported include module

urlpatterns = [
	path('', include('blog.urls')), #added
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

Let’s finally create templates for blog app

Django’s templates are called views in other MVC framework. In the templates/index.html file, we’ll iterate (with for in iterator/loop) through the articles variable that holds all Article objects. Variable is accessible to the index.html file via index method in

List Article View

<!DOCTYPE html>
	<title>Django Blog App</title>

	{% for article in articles %}
		<a href="{% url 'single'}"><h2>{{article.title}}</h2></a>
		<p>Posted in: {{article.category}}, Posted by: {{}}</p>
		<img src="{{article.image.url}}" alt="{{article.title}}">
	{% endfor %}


Single Article view

<!DOCTYPE html>
<html lang="en">
	<meta charset="UTF-8">
	<title>Django Blog Single Page</title>

	<a href="{% url 'index' %}">...Go Back</a>

	<p>Posted in: {{single.category}}, Posted by: {{}}</p>
	<img src="{{single.image.url}}" alt="{{single.title}}">

Watch me Build this very same application

Part #2

Learn Django Templating Language – Jinja

This is second part in the series of ‘Learn Django 3: by building a blogging app’ .

In this section you will learn to create basics templates in Django 3. You will learn to create base template with Jinja template language for Python.

Here are few things that I am going to cover in this section.

  1. Jinja Syntax
  2. Jinja Blocks
  3. Jinja Extends function
  4. Jinja for in iterator
  5. Jinja url function

Part #3

Django 3: Static Files – images, JS, CSS, and Bootstrap 4

In this section, you will learn to add and manage static files in Django 3 Framework project. I will demonstrate how uploading and displaying images work, and at the same time I’ll show you how you can add JavaScript, CSS files and most importantly Bootstrap 4 with CDN and compiled source files locally as well.

You will learn to ..

  1. Upload and Display Images
  2. Add JavaScript files
  3. Add CSS files
  4. Add Bootstrap 4 with CDN
  5. Add Bootstrap 4 Compiled Source Files Locally


    os.path.join(BASE_DIR, 'static'),

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')


urlpatterns = [
	path('', include('blog.urls')),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Part #4

Style Django 3 App with Bootstrap 4.4

This is the fourth video in the series of Learn Django 3 by building a blogging app. In this video, I’ll style my blogging app with Bootstrap 4.4. In the previous video, I added Bootstrap 4.4 source files locally to the Django 3 project.

Here are the things that you’ll learn in this section of styling Django app with Bootstrap 4.4

  1. Adding Navigation Bar to the Django App
  2. Adding links to Django Nav Bar
  3. Creating Bootstrap Card to display Article list
  4. Style Article single view page

Part #5

In this section, you learn to create pagination for your blog app article index page using Django Core Paginator class. And you’ll also learn to create Previous and Next buttons for your single article page.

You will learn following Django concepts..

  1. How to use Paginator class in a view (list view)
  2. Implementation of pagination in template page index.html
  3. How to create Django Previous & Next button for single post
  4. How to use Django Model QuerySet filter() method

By Tube Mint

I am a YouTuber and I also do niche marketing. In the process of create my niche blog using WordPress, Drupal, and GatsbyJS, I learned a few things like html, css, JS, CMS, MVC frameworks, C++, Python, Ruby, MySQL, Windows and Linux. After some time.. I realized that I can share my knowledge with people on YouTube and through my blog. So, here I am. You can ask me if you have any question about these technologies.