最近刚开始学习flask开发,在做一个留言板的网站,通过视图函数渲染模板时,报错
File "C:\Users\Administrator\Desktop\FlaskProgram\TalkTo\templates\base.html", line 14, in template
Say Hello
https://ask.csdn.net/%7B%7B%20url_for('index')%20%7D%7D
jinja2.exceptions.TemplateSyntaxError: expected token ',', got 'index'
以下是模板
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>{% block title %}Talk To the World!{% endblock title %}</title>
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css) }}" type="text/css">
</head>
<body>
<main class="container">
<header>
<h1 class="text-center display-4">
<a href="{{ url_for('index') }}" class="text-danger"><strong>Say Hello</strong></a>
<small style="font-size: 24px" class="text-muted">to the world</small>
</h1>
</header>
{%for message in get_flashed_messages()%}
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">×</button>
{{message}}
</div>
{%endfor%}
{%block content%}{%endblock content%}
<footer class="text-center">
{%block footer%}
...
<p><a id="bottom" href="#" title="Go Top">↑</a> </p>
{%endblock footer%}
</footer>
</main>
<script type="text/javascript" src="{{ url_for('static', filename='js/jquery-3.2.1.slim.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/popper.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/script.js') }}"></script>
{{ moment.include_moment(local_js=url_for('static', filename='js/moment-with-locales.min.js') }}
{{ moment.locale(auto-detect=Ture) }}
</body>
</html>
以下是视图函数
@app.route('/index', methods=['GET', 'POST'])
def index():
# 加载所有数据,用于模板渲染,展示数据
messages = Message.query.order_by(Message.timestamp.desc()).all()
form = TalkForm() # 实例化表单
if form.validate_on_submit(): # 验证提交
name = form.name.data
body = form.body.data
message = Message(body=body, name=name) # 实例化模型类
db.session.add(message) # 添加到数据库会话
db.session.commit() # 提交会话(储存数据)
flash('Message submitted successfully.')
return redirect(url_for('index')) # 重定向至当前页面,get方法展示提交的数据
return render_template('index.html', form=form, messages=messages)
实在是查不出问题出在哪里,看起来模板上的语法没有问题,辛苦大家帮忙看看为什么会这样呢