Python Django Project – Blog Web Application

In this article, we will learn to build an interesting project using django – Blog Web Application

Django is an open source python web framework that follows model view template (MVT) architectural pattern. It is easy to learn and use, so you can easily understand this project even if you have no or less knowledge of django.

A blog application will have the following fields:

  • Title of the blog
  • Description
  • Image
  • Likes


  • See existing blogs.
  • Create new blogs.
  • Like existing blogs.

Keeping you updated with latest technology trends, Join TechVidvan on Telegram

Project Prerequisites

We will use the following technologies / tools:

  1. Python
  2. HTML
  3. CSS
  4. Bootstrap
  5. Django framework

To install the framework, you can type the following on your cmd/terminal.

pip install Django

Download Django Blog Application Source Code

Please download the source code of blog web application in django: Blog Application Project Code

Steps to Create Blog Application in Python Django

1. Writing Models

We will need only one model class that will store blogs and the fields are already discussed above and here is the code.


from django.db import models

# Create your models here.
class Blogs(models.Model):



from .models import *
from django import forms
from django.forms import ModelForm

class blogForm(ModelForm):
    class Meta:

Here, we are using Django’s ModelForm class to make an create blog form which will have all the fields except likes and date because date will be automatically filled and the creator shouldn’t have access to modify likes.3.

To access models on admin site we need to first make a super user, so type the following command in cmd

Py createsuperuser

After creating super user we need to register the model in


from django.contrib import admin
from .models import *

# Register your models here.



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

We will use ImageField to upload images, so we need to configure MEDIA_URL in

So for configuring please append above code in and then follow the next step.



from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from blog.views import *

urlpatterns = [
    path('', home,name='home'),
]+ static(settings.MEDIA_URL ,document_root=settings.MEDIA_ROOT)

6. :


from django.shortcuts import render,redirect
from .models import *
from .forms import *

# Create your views here.
def home(request):
    return render(request,'home.html',context)

def addBlog(request):
    if request.method=='POST':
        if form.is_valid():
            return redirect('/')
    return render(request,'addblog.html',context)

def likeBlog(request,pk):
    return redirect('/')

We have created three functions in this file:

1.Home: It stores all the blog objects in ‘AllBlogs’ and pass them to home.html


{% load static %}
            Techvidvan Blog Application
        <link rel="stylesheet" href="" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
        <link rel="stylesheet" href=" {% static '/css/main.css' %} ">
        {% block content %} 
        <div class="container">
            <a href="{% url 'addblog' %}" class='btn btn-primary'>Add Blog</a>
        {%for b in blogs %}  
            <div class="row">
                <div class="col-md-3">
                    <div class="card" style="width: 22rem;">
                        <img src="{{b.Image.url}}" class="card-img-top" alt="">
                        <div class="card-body">
                        <h5 class="card-title">{{b.title}}</h5>
                        <p class="card-text">{{b.description}}</p>
                        <form action='{%  url 'like' %}' method=POST>
                            {% csrf_token %}
                            <button type='submit' class='btn btn-success'>{{b.likes}} Like</button>
                        <p class="card-text">Published on: {{}}</p>                
        {% endfor %}
        {% endblock %}


In this file, We are displaying all the stored blogs in separate bootstrap cards.

We have used bootstap for all the designing part so there is no CSS code required.

2. addBlog: It uses blogForm to create a form and pass it to addblog.html and addblog.html again calls this function with POST request, then it checks the validation of the form and after checking it saves it in the database abd redirects to the home page.


{% extends 'home.html' %}
{% load static %}
{% block content %}
<div class="container " style="border:5px solid black">
    <form action="" method='POST' enctype="multipart/form-data">
        {% csrf_token %}
        <input class="btn btn-success" type="submit" name="Add">
{% endblock %}

Django Blog Web Application Output

add blogs

blog home page


We have successfully developed Django Blog Web Application. This project will surely help you to become a pro in Python Django

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.