2 回答

TA贡献1802条经验 获得超6个赞
我修好了它。
我现在的代码是这样的:
@app.route('/posts/<postid>', methods=["GET", "POST"])
@login_required
def posts(postid):
post = Posts.query.filter_by(id=postid).first()
if request.method == "POST":
comment = request.form.get('comment')
c = Comments(id=len(Comments.query.all())+1, comment=comment, user=current_user.username, postid=postid)
db.session.add(c)
db.session.commit()
return redirect('/posts/{}'.format(postid))
# c = Comments()
# print(json.dumps(c, cls=AlchemyEncoder))
comments = Comments.query.filter_by(postid=postid).all()
print(Comments.query.all())
return render_template("post.html", title=post.title, body=post.body, user=post.user, id=postid, comments = [comment_dict(comment) for comment in comments])
编辑:我根据下面的 Attack68 答案得出了这个答案。给他荣誉,而不是我:)
添加回答
举报