首页 新闻 会员 周边 捐助

报错werkzeug.routing.BuildError: Could not build url for endpoint 'main.user'. Did you forget to specify values ['username']?

0
[待解决问题]

html模板为

index模板:

{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block title %}博客{% endblock %}

{% block page_content %}
<div class="page-header">
<h1>您好, {% if current_user.is_authenticated %}{{ current_user.username }}{% else %}游客{% endif %}!</h1>
</div>
<div>
{% if current_user.can(Permission.WRITE_ARITICLES) %}
{{ wtf.quick_form(form) }}
{% endif %}
</div>
{% include '_posts.html' %}
{% endblock %}

_post.html模板为:
<ul class="posts">
{% for post in posts %}
<li class="post">
<div class="post-thumbnails">
<a href="{{ url_for('.user', username=post.author.username) }}">
<img class="img-rounded profile-thumbnails" src="{{ url_for('static', filename='avatar/') }}{{ post.author.gravatar() }}">
</a>
</div>
<div class="post-content">
<div class="post-date">{{ moment(post.timestamp).fromNow() }}</div>
<div class="post-author"><a href="{{ url_for('.user', username=post.author.username) }}">{{ post.author.username }}</a></div>
<div class="post-body">{{ post.body }}</div>
</div>
</li>
{% endfor %}
</ul>

视图函数为:
@main.route('/', methods=['GET','POST'])
def index():
form = PostForm()
if current_user.can(Permission.WRITE_ARTICLES) and \
form.validate_on_submit():
post = Post(body = form.body.data, author=current_user._get_current_object())
db.session.add(post)
return redirect(url_for('.index'))
posts = Post.query.order_by(Post.timestamp.desc()).all()
return render_template('index.html',form=form, posts=posts)


@main.route('/user/<username>')
def user(username):
print(username)
user = User.query.filter_by(username=username).first_or_404()
posts = user.posts.order_by(Post.timestamp.desc()).all()
return render_template('user.html', user=user,posts =posts)


这是怎么回事,哪位大神帮忙看看,万分感谢

左手十字的主页 左手十字 | 菜鸟二级 | 园豆:204
提问于:2017-09-07 14:54
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册