Python Django{%extend static";template.html";%}抛出TemplateSyntaxError
我有一个template.html文件,其中包含一些锅炉板html文本 然后在index.html中,我有:Python Django{%extend static";template.html";%}抛出TemplateSyntaxError,python,html,django,Python,Html,Django,我有一个template.html文件,其中包含一些锅炉板html文本 然后在index.html中,我有: {%load static%} {%extends static'template.html%} 在settings.py中,我有(相关内容): 已安装的应用程序=[ 'notes.apps.NotesConfig', “django.contrib.admin”, “django.contrib.auth”, “django.contrib.contenttypes”, “djang
{%load static%}
{%extends static'template.html%}
在settings.py中,我有(相关内容):
已安装的应用程序=[
'notes.apps.NotesConfig',
“django.contrib.admin”,
“django.contrib.auth”,
“django.contrib.contenttypes”,
“django.contrib.sessions”,
“django.contrib.messages”,
“django.contrib.staticfiles”,
]
静态URL='/STATIC/'
然而,当我试图呈现index.html时,我得到了一个
“extends”处的TemplateSyntaxError接受一个参数。
当template.html与index.html放在同一目录中时,我使用了
{%extends'template.html%}
一切正常。似乎需要添加对静态文件夹的引用,以便Django知道在哪里查找静态文件。 为此,您需要在
settings.py
文件中添加以下代码行。
假设在基本目录中有一个用于存放静态文件的文件夹,即manage.py
文件所在的位置。只需将以下行添加到设置.py
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'staticfiles'),
]
# Assuming the name of your static files folder is "staticfiles"
如果在模板中使用{%extends%},则它必须是该模板中的第一个模板标记。否则,模板继承将无法工作
我们将根据,所以我不确定你可以加载静态
问题是为什么要扩展static?将其移动到模板,然后以常规方式进行扩展