在 Flask 应用程序中有两个文件:
base.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="../static/main.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.1/css/bootstrap.min.css">
<title>Title</title>
</head>
<body>
<div id="content">
{% marker "content" %}
</div>
</body>
</html>
upload.html
,它扩展了 base.html
{% extends "base.html" %}
{% block "content " %}
<title>Upload new File</title>
<h1>Upload new File</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
{% endblock %}
我在 View 中调用后者:return render_template('upload.html' )
,但出现错误:
jinja2.exceptions.TemplateSyntaxError
TemplateSyntaxError: expected token 'name', got 'string'
最佳答案
问题是 {% block "content"%}
应该是 {% block content %}
- block 的名称不应该被引用。
此外,您的 layout.html 中的 marker
结构是 not a valid Jinja2 tag - 它应该是 {% block content %}{% endblock %}
。
关于python - 神社 : TemplateSyntaxError: expected token 'name' , 得到 'string',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15823989/