python - 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’'
似乎是什么导致了语法错误?
提前致谢
解决方案
而不是{% extends ‘layouts/master.html’ %}
使用{% extends 'layouts/master.html' %}
推荐阅读
- vue.js - 如何在 vuejs 中使用自定义指令更改字体大小
- r - 如何重新计算列并将新值存储在同一数据框中?
- php - 如何反转一组逗号分隔的字符串并在 PHP 中以原始顺序返回它们?
- mysql - 数据建模和实现关系[1对多][多对多]等
- node.js - 我可以在不安装 Express 的情况下使用 body-parser 模块吗?
- c++ - 如何从 phinode 及其在 LLVM 中的相应基本块中获取标签?
- node.js - 号码的 Hapi/Joi 验证失败
- php - 未定义的偏移量 [PHP / JQUERY]
- typescript - 嵌套函数调用中的打字稿异步等待
- git - Git将不同的分支推送到不同的远程仓库?