Could not parse the remainder: '%if context %' from '%if context %' [duplicate]

This is my views.py :

from django.shortcuts import render
from django.http import HttpResponse

posts= [
    {
    'author' : 'sahil tariq',
    'title' :'Blog post 1',
    'content': 'First blog post',
    'date' : '12 sep , 2022'
    },
    {
    'author' : 'Hanan ',
    'title' :'Blog post 2',
    'content': 'Second blog post',
    'date' : '13 sep , 2022'
    }
]
def home(request):
    context = {
        'posts': posts
    }
    return render(request, 'blog/home.html' , context)

def about(request):
    context = {
        'title' : 'About'
    }
    return render(request, 'blog/about.html', context)

this is my home.html:

<!DOCTYPE html>
<html>

<head>
    {{% if title %}}
        <title>Django Blog - {{ title }}</title>
    {{% else %}}
        <title>Django Blog</title>
    {{% endif %}}
</head>

<body>
    {% for post in posts %}
    <h1>{{ post.title }}</h1>
    <p> By {{ post.author }} on {{ post.date }}</p>
    <p> {{post.content}}</p>
    {% endfor %}
</body>

</html>

So what I am trying to do is display the page title if there is one title present in the jinja if statement but it shows me an error when I try to run the if statement in home.html.

Back to Top