首页 > 解决方案 > Django:TemplateSyntaxError:无法解析剩余部分(扩展标签)

问题描述

当我访问http://127.0.0.1:8000/时出现此错误

我已经经历了其他类似的线程,并尝试过使用空格以及单引号和双引号,但没有运气。我试图让 index.html 文件继承 master.html 中的代码,该代码包含在一个看起来像这样的文件夹结构中。

以下是我认为导致此错误的一些文件的一些片段:

来自settings.py:

BASE_DIR = Path(__file__).resolve().parent.parent

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'tracker',
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

来自index.html(这是该文件中唯一的一行)

{% extends ‘layouts/master.html’ %}

来自views.py

# Create your views here.
from django.shortcuts import render
def index(request):
    return render(request, 'index.html')

错误回溯:

Exception Type: TemplateSyntaxError at /
Exception Value: Could not parse the remainder: '‘layouts/master.html’' from '‘layouts/master.html’'

似乎是什么导致了语法错误?

提前致谢

标签: pythonpython-3.xdjangodjango-templates

解决方案


而不是{% extends ‘layouts/master.html’ %}使用{% extends 'layouts/master.html' %}


推荐阅读