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

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

 

 1 <ul class="list-group" style="margin-top: 30px;">
 2                     <h1>全部评论</h1>
 3                     {% for com in comment %}
 4                         <li class="list-group-item" style="width: 800px">
 5                             <a class="wrap-img" href="#" target="_blank">
 6                                 <img src="http://www.bookmarkye.com/3.jpg" width="50px">
 7                             </a>
 8                             <span class="glyphicon glyphicon-left" aria-hidden="true"></span>
 9                             <a href="{{ url_for('comment',user_id=com.author.id) }}"
10                                target="_blank">{{ com.author.username }}</a>
11                             <br>
12                             <span class="badge">{{ com.creat_time }}</span>
13                             <p style="">{{ com.detail }}</p>
14                         </li>
15                     {% endfor %}
16                 </ul>

 

 

 

2.所有评论排序
uquestion = db.relationship('Question', backref=db.backref('comments', order_by=creat_time.desc))

 1 <ul class="list-group" style="">
 2                     <h1>全部问题</h1>
 3                     {% for foo in questions %}
 4                         <li class="list-group-item" style="width: 800px">
 5                             <a class="wrap-img" href="#" target="_blank">
 6                                 <img src="http://www.bookmarkye.com/3.jpg" width="50px">
 7                             </a>
 8                             <span class="glyphicon glyphicon-left" aria-hidden="true"></span>
 9                             <a href="{{ url_for('comment',user_id=foo.author.id) }}"
10                                target="_blank">{{ foo.author.username }}</a>
11                             <br>
12                             <a href="{{ url_for('detail',question_id=foo.id) }}">{{ foo.title }}</a>
13                             <span class="badge">{{ foo.creat_time }}</span>
14                             <p style="">{{ foo.detail }}
15                             </p>
16                         </li>
17                     {% endfor %}
18                 </ul>

 

 

3.显示评论条数
{{ ques.comments|length }}

1          <div class="list-group-item" style="margin-top: 30px;width: 800px;">
2                     <h1>名称:<small>{{ user.username }}</small></h1>
3                     <h1>问题数:<small>{{ questions|length }}</small></h1>
4                     <h1>评论数:<small>{{ comment|length }}</small></h1>
5                 </div>

 

4.完成个人中心

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

  

1 <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
2     <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
3     <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>

 

 

 

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

 

 1 # 某用户发布过的所有评论
 2 @app.route('/comment/<user_id>',methods=['GET','POST'])
 3 def comment(user_id):
 4     user = User.query.filter(User.id == user_id).first()
 5     content = {
 6         'comment':user.comment,
 7         'questions':user.question,
 8         'user2':user
 9     }
10     return render_template('comment.html', **content)

 

 

 

  3.向前端页面传递参数

  4.页面显示相应数据

    发布的全部问答

      

    发布的全部评论

      

    个人信息

      

 

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

      

转载于:https://www.cnblogs.com/-064/p/8027203.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值