博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
完成评论功能
阅读量:4628 次
发布时间:2019-06-09

本文共 1263 字,大约阅读时间需要 4 分钟。

    1. 定义评论的视图函数
      @app.route('/comment/',methods=['POST'])
      def comment():
      读取前端页面数据,保存到数据库中
      @app.route('/comment/', methods=['POST'])@loginFirstdef comment():    comment = request.form.get('new_comment')    ques_id = request.form.get('question_id')    author_id = User.query.filter(User.username == session.get('user')).first().id    comm= Comment(author_id=author_id, question_id=ques_id, detail=comment)    db.session.add(comm)    db.session.commit()    return redirect(url_for('detail', question_id=ques_id))
    2. 用<input type="hidden" 方法获取前端的"question_id" 
    3. 显示评论次数
      评论:({
      { ques.comments|length }})
    4. 要求评论前登录
    5. 尝试实现详情页面下的评论列表显示
      def loginFirst(func):    @wraps(func)    def wrapper(*args, **kwargs):        if session.get('user'):            return func(*args, **kwargs)        else:            return redirect(url_for('login2'))    return wrapper

       

转载于:https://www.cnblogs.com/222ya/p/8004804.html

你可能感兴趣的文章
WebFrom模拟MVC
查看>>
人机猜拳(这是最近的一个总结)
查看>>
python函数
查看>>
模板引擎:Velocity&FreeMarker(转)
查看>>
Anaconda安装,jupyter notebook 使用说明
查看>>
sql server 2014预览版发布
查看>>
正则表达式string对象方法
查看>>
解析json实例
查看>>
spring中实现自己的初始化逻辑
查看>>
Accommodation development for Kaikoura
查看>>
Oracle11.2新特性之listagg函数 (行列转换)
查看>>
Flutter学习之动态ListView
查看>>
myeclipse中安装svn插件
查看>>
微信小程序----调用用户信息
查看>>
Ubuntu系统---安NVIDIA 驱动后 CUDA+cuDNN 安装
查看>>
Spring Boot配置全局异常捕获
查看>>
Java 的zip压缩和解压缩
查看>>
SPOJ375(树链剖分)
查看>>
C基础知识小总结(十)
查看>>
Ignatius and the Princess IV (水题)
查看>>