我正在使用 Python 和 Flask 框架来写一个微博。
File "/home/akoppad/flaskblog/app/templates/base.html", line 27, in top-level template code
{% block content %}{% endblock %}
File "/home/akoppad/flaskblog/app/templates/edit.html", line 13, in block "content"
[Display the sourcecode for this frame] [Open an interactive python shell in this frame]
{{form.nickname(size=60)}}
这是我的代码。
@app.route('/edit', methods=['GET','POST'])
@login_required
def edit():
form=EditForm(g.user.nickname)
if form.validate_on_submit():
g.user.nickname = form.nickname.data
g.user.about_me = form.about_me.data
db.session.add(g.user)
db.session.commit()
flash('Your changes have been saved.')
return redirect_url(url_for('edit'))
elif request.method !="POST":
form.nickname = g.user.nickname
form.about_me = g.user.about_me
else:
form.nickname.data = g.user.nickname
form.about_me.data = g.user.about_me
flash(form.nickname)
flash("inside edit")
return render_template('edit.html', form=form)
<form action="" method="post" name="edit">
{{form.hidden_tag()}}
<table>
<tr>
<td>Your nickname:</td>
<td>
{{form.nickname(size = 24)}}
{% for error in form.errors.nickname %}
<br><span style="color: red;">[{{error}}]</span>
{% endfor %}
</td>
</tr>
<tr>
<td>About yourself:</td>
<td>{{form.about_me(cols = 32, rows = 4)}}</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Save Changes"></td>
</tr>
</table>
</form>
我在视图中放置了一个闪存状态,它返回正确的值。如果我删除(size=60)
并打印 form.nickname,它会正确打印。没有问题。当我有 size=60 时会抛出错误。请让我知道为什么会发生错误。
对于那些有兴趣了解更多信息的人,我正在关注本教程,这里