评论列表显示及排序,个人中心显示

1.显示所有评论
{% for foo in ques.comments %}

<ul class="comment">
        {% for foo in question.comments %}
        <span class="icon" aria-hidden="true"><img src="../static/images/icon.jpg"></span>
        <a href="{{ url_for('self',user_id=foo.author_id) }}" class="name">{{ foo.author.username }}</a>
         <span class="badge2">{{ foo.creatTime }}</span>
           <br>
        <p class="neirong">{{ foo.detail }}</p>

        {% endfor %}
    </ul>

2.所有评论排序

uquestion = db.relationship('Question', backref=db.backref('comments', order_by=creat_time.desc))

   question = db.relationship('Question', backref=db.backref('comments',order_by=create_time.desc))

3.显示评论条数

{{ ques.comments|length }}

<span class="tcomment">评论:({{ ques.comments|length }})</span>

4.完成个人中心

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

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

   3.向前端页面传递参数

   4.页面显示相应数据

   发布的全部问答

   发布的全部评论

  个人信息

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

@app.route('/usercenter/<user_id>')
@loginFirst
def usercenter(user_id):
    user = User.query.filter(User.id == user_id).first()
    context={
        # 'username':user.username,
        # 'question':user.questions,
        # 'comments';user.comments
        'user':user
    }

    return render_template('usercenter.html',**context)
{% extends'base.html' %}
{% block title %}
    用户中心
{% endblock %}
{% block head %}
<link rel="stylesheet" href="{{ url_for('static',filename='css/usercenter.css')}}" type="text/css">
{% endblock %}
{% block main %}
    <div class="big">
<div class="content">

    <h3><span class="glyphicon-leaf" aria-hidden="true"></span><img id="qu" src="{{ url_for('static',filename='images/question.jpg')}}">
    {{ user.username }}<br><small>全部问答:</small></h3>
<ul class="list-group">
 {% for foo in user.question %}
      <li class="list-group-item">
        <span class="glyphicon-leaf" aria-hidden="true"></span>
              <img id="qu" src="{{ url_for('static',filename='images/question.jpg')}}">
          <a href = "">{{ foo.author.username }}</a>
       <span class="badge">评论时间:{{ foo.create_time }}</span>
        <p style="text-align: left">{{ foo.detail }}</p>
</li>
    {% endfor %}
  </ul>
</div>
<div class="content">

    <h3><span class="glyphicon-leaf" aria-hidden="true"></span>
 <img id="qu" src="{{ url_for('static',filename='images/question.jpg')}}">
 {{ user.username }}<br><small>全部评论:</small></h3>
<ul class="list-group">
 {% for foo in user.comments %}
      <li class="list-group-item">
        <span class="glyphicon-leaf" aria-hidden="true"></span>
              <img id="qu" src="{{ url_for('static',filename='images/question.jpg')}}"><a href = "">{{ foo.author.username }}</a>
       <span class="badge">评论时间:{{ foo.create_time }}</span>
        <p style="text-align: left">{{ foo.detail }}</p>
</li>
    {% endfor %}
  </ul>
</div>

<div class="content">
     <h3><span class="glyphicon-leaf" aria-hidden="true"></span>
 <img id="qu" src="{{ url_for('static',filename='images/question.jpg')}}">
         {{ user.username }}<br>
         <small>个人信息:</small></h3>
    <ul class="list-group">
        <li class="list-group-item">用户:{{ user.username }}</li>
        <li class="list-group-item">编号:{{ user.id }}</li>
        <li class="list-group-item">昵称:{{ user.nickname }}</li>
        <li class="list-group-item">文章篇数:{{ user.question|length }}</li>
    </ul>
</div>
    </div>
{% endblock %}

 

posted @ 2017-12-13 21:00  073徐英杰  阅读(186)  评论(0编辑  收藏  举报