zoukankan      html  css  js  c++  java
  • 评论列表显示及排序,个人中心显示

    1. 显示所有评论
      {% for foo in ques.comments %}
        {% for each in comments %}
                                  <li class="list-group-item" >
                                  <a  class="author" href="">{{ each.author.username }}</a>
                                  <br>
                                      <br>
                                      <span >{{ each.create_time }}</span>
                              <p class="abstract">{{ each.detail }}</p>
                                  </li>
                                  {% endfor %}
      
    2. 所有评论排序
      uquestion = db.relationship('Question', backref=db.backref('comments', order_by=creat_time.desc))
      question = db.relationship('Question', backref=db.backref('comment', order_by=create_time.desc()))
      
    3. 显示评论条数
      {{ ques.comments|length }}
      <h4>评论:({{ ques.comment|length }})</h4>
      
    4. 完成个人中心

    1.个人中心的页面布局(html文件及相应的样式文件)

    2.定义视图函数def usercenter(user_id):

    3.向前端页面传递参数

    4.页面显示相应数据

    发布的全部问答

    发布的全部评论

    个人信息

    @app.route('/userCenter/<user_id>', methods=['GET'])
    def userCenter(user_id):
        user = User.query.filter(User.id == user_id).first()
        context = {
            'username': user.username,
            'questions': user.question,
            'comments': user.comment
        }
        return render_template('userCenter.html', **context)
    

      

    5.各个页面链接到个人中心

    href="{{ url_for ('userCenter',user_id=each.author.id) }}"
    

    每个页面用这句代码做相应修改即可

  • 相关阅读:
    js写的ajax
    String根据、拆分
    Excel数据批量导入到数据库2
    Excel数据批量导入到数据库
    List去重复(不是最简单,但绝对是最易理解)
    struts中Cookie实现记住密码
    ==与equals的区别
    javascript实现登录验证码
    Javascript实现二级select联动
    javascript的假查询
  • 原文地址:https://www.cnblogs.com/mavenlon/p/8027225.html
Copyright © 2011-2022 走看看