zoukankan      html  css  js  c++  java
  • 完成评论功能

    1、定义评论的视图函数
    @app.route('/comment/',methods=['POST'])
    def comment():
    读取前端页面数据,保存到数据库中

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

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

    3、显示评论次数

    4、要求评论前登录

    @loginFirst

    5、尝试实现详情页面下的评论列表显示

    {% extends 'jianshu.html' %}
    {% block title %}问答详情{% endblock %}
    
    {% block main %}
        <div class="page-header">
            <h3>题目:{{ pos.title }}
                <br>
                <small>作者:{{ pos.author_id }}发布时间:{{ pos.creat_time }}
                </small>
            </h3>
        </div>
        <p class="lead">详情:{{ pos.detail }} </p>
        <br>
        <form action="{{ url_for('comment') }}" method="post">
        <div class="form-group">
            <textarea name="new_comment" id="new_comment" rows="5" placeholder="请写下你的评论"></textarea>
            <input name="post_id" type="hidden" value="{{ pos.id }}">
        </div>
        <button type="submit" class="btn btn-default">发送</button>
        </form>
        <h4>评论:({{ pos.comments|length }})</h4>
    
        <ul class="list-group" style="margin: 10px"></ul>
    {% endblock %}
  • 相关阅读:
    路由器远程登陆的方式
    路由器上的DNS服务器构建
    路由器配置维护技巧---管道的应用
    【转】常见面试问题
    英文面试决胜关键
    12个有趣的c语言面试题
    16道嵌入式C语言面试题(经典)
    LCD 调试总结
    关于uboot的一些优化
    linux驱动开发的经典书籍
  • 原文地址:https://www.cnblogs.com/lintingting/p/8005987.html
Copyright © 2011-2022 走看看