无法解析其余部分:"('静态',文件名='main.png')"来自"url_for('static', filename='main.png')'



我是一个django初学者,我正在尝试呈现一个html页面。我已经有一个测试html页面和URL来测试它。

点击 URL 后,会遇到以下错误:

Could not parse the remainder: '('static', filename='main.png')' from 'url_for('static', filename='main.png')'

完整跟踪:

Request Method:
GET
Request URL:
http://127.0.0.1:8000/xxxxx
Django Version:    3.0.2
Exception Type:    TemplateSyntaxError
Exception Value:    Could not parse the remainder: '('static', filename='main.png')' from 'url_for('static', filename='main.png')'
Exception Location:    F:Anacondalibsite-packagesdjangotemplatebase.py in __init__, line 662
Python Executable:    F:Anacondapython.exe
Python Version:    3.7.0

我尝试使用单引号和双引号,但它仍然不起作用。 有点卡在这一点上。

任何意见/建议/提示/指南链接不胜感激。

看看这个。你必须确保使用{% load static %}在模板中加载静态,然后你可以让 django 使用{% static "static/path.ext" %}生成指向模板中文件的链接

因此,您可以将文件更改为:

.bg-image {
background-image: url("{% static "main.png" %}");
filter: blur(8px);
-webkit-filter: blur(8px);
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}

请记住将{% load static %}放在文件的顶部。

最新更新