Не удалось разобрать остаток: '%if context %' из '%if context %' [дубликат].

Вот мой 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)

Это мой дом.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>

Итак, я пытаюсь отобразить заголовок страницы, если есть один заголовок, присутствующий в операторе jinja if, но он показывает мне ошибку, когда я пытаюсь запустить оператор if в файле home.html.

Вернуться на верх