首页 > 其他 > 详细

完成评论功能

时间:2017-12-08 13:02:38      阅读:137      评论:0      收藏:0      [点我收藏+]
    1. 定义评论的视图函数
      @app.route(‘/comment/‘,methods=[‘POST‘])
      def comment():
      读取前端页面数据,保存到数据库中
    2. 用<input type="hidden" 方法获取前端的"question_id" 
    3. 显示评论次数
    4. 要求评论前登录
    5. 尝试实现详情页面下的评论列表显示
@app.route(/comments,methods=["POST"])
@login_first
def comments():
    comment = request.form.get("detail1")
    author_id = Question.query.filter(User.username == session.get(user)).first().id
    ques_id = request.form.get("question_id")
    comm = Comment(detail=comment, author_id=author_id,question_id=ques_id)
    db.session.add(comm)
    db.session.commit()
    return redirect(url_for(detail,question_id=ques_id))
<form action="{{ url_for("comments") }}" method="post">
            <div>

                <textarea  style="width: 400px"  id="xiang" rows="5" name="detail1" placeholder="请输入您的评论"></textarea><br>
                <input style="display: none" value="{{ ques.id }}" name="question_id"/>
                <input  type="submit" value="发送" style="width:45px;height:25px;font-size:15px">
                </div>
        </form>
            <div>
                <h4 >评论:({{ ques.comment|length }})</h4>

 

完成评论功能

原文:http://www.cnblogs.com/yin-yeah/p/8004825.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!