2017-09-27 95 views
0

当我点击“评论”链接时,我该如何显示发表评论?Python烧瓶|显示帖子评论

我只想显示用户的一个帖子,但它只显示用户名。

Models.py

class Post(db.Model): 
    __searchable__ = ["body"] 

    id = db.Column(db.Integer, primary_key=True) 
    body = db.Column(db.String(140)) 
    timestamp = db.Column(db.DateTime) 
    user_id = db.Column(db.Integer, db.ForeignKey('user.id')) 

def __repr__(self): 
    return self.body 

Views.py

@app.route("/comment/<username>") 
@app.route("/comment/<username>/<int:page>") 
@login_required 
def comment(username, page=1): 
    form = CommentForm() 
    user = User.query.filter_by(username=username).first() 
    if form.validate_on_submit(): 
     return redirect(url_for('comment')) 
    posts = user.followed_posts().paginate(page, POSTS_PER_PAGE, False) 
    return render_template("comment.html", form=form, username=username, user=user, posts=posts) 

Comment.html

{{ username }} 
{{ body }} 
<form action="" method="POST"> 
    {{ form.hidden_tag() }} 
    {{ form.comment(size=auto) }} 
    <button class="send-comment"> Kirim </button> 
</form> 

回答

0

我不能看到你 “返回” 变量 “身体” 来的Jinja2当呈现comment.html时。

也许你应该在你的“comment.html”文件中将{{ body }}更改为{{ posts }}

+0

哦,是啊,我的意思是在这里想添加单个帖子评论像facebook 当我添加{{post.body}} 所以我得到所有帖子从用户原因循环,所以我想显示帖子,我会给评论 – user8489260