完成评论功能

时间:2017-12-08 21:31:41   收藏:0   阅读:218

1、定义评论的视图函数

@app.route(/comment,methods=[POST])
def comment():
    comment =request.form.get(new_comment)
    wenda_id=request.form.get(wenda_id)
    auth_id=User.query.filter(User.username==session.get(user)).first().id
    comm = Comment(author_id=auth_id,wenda_id=wenda_id,detail=comment)
    db.session.add(comm)
    db.session.commit()
    return redirect(url_for(detail,wenda_id=wenda_id))

 

2、用<input type="hidden" 方法获取前端的"question_id" 

<input id="wenda_id" name="wenda_id" type="hidden" value="{{ wen.id }}">

 

3、显示评论次数

<h4>评论:({{ wen.comment|length}})</h4>

 

4、要求评论前登录

@loginFirst

 

原文:http://www.cnblogs.com/honghui/p/8007013.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!