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

usercenter.html代码

 1 <!doctype html>
 2 <html lang="en">
 3 <head>
 4 
 5     <style>
 6         .nav_ul li{
 7             float: left;
 8             list-style: none;
 9             margin: 10px;
10             border-bottom: outset;
11         }
12     </style>
13     <meta charset="UTF-8">
14     <meta name="viewport"
15           content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
16     <meta http-equiv="X-UA-Compatible" content="ie=edge">
17     <title>个人中心</title>
18 </head>
19 <body>
20 <ul class="nav_ul">
21     <li role="presentation"><a href="#">全部提问</a></li>
22     <li role="presentation"><a href="#">全部评论</a></li>
23     <li role="presentation"><a href="#">个人信息</a></li>
24 
25 </ul>
26  <div class="col-md-6 column ">
27         <div class="page-header"> {% for foo in wenda %}
28             <div class="panel panel-default">
29                 <div class="panel-heading">
30                     <h3 class="panel-title">
31                         <a href="{{ url_for('detail',wenda_id=foo.id) }}">标题:{{ foo.title }}</a><br>
32                     </h3>
33                     <a href="{{ url_for('usercenter',user_id=foo.author_id) }}">作者:{{ foo.author.username }}</a>
34                 </div>
35 
36                 <div class="panel-body">
37                     <a href="#">内容:{{ foo.detail }}</a><br>
38                 </div>
39                 <div class="panel-footer">
40                     <span class="badge" style="margin-left: 60%">{{ foo.creat_time }}发布时间</span>
41                 </div>
42             </div>
43             {% endfor %}
44         </div>
45     </div>
46 
47     <div class="col-md-6 column ">
48     <div class="page-header">{% for foo in comments %}
49         <li class="list-group-item">
50             <a href="{{ url_for('usercenter',user_id=foo.author_id) }}">{{ foo.author.username }}</a>
51             <span class="badge pull-right">{{ foo.create_time }}</span>
52             <p>{{ foo.detail }}</p>
53             <br>
54         </li>
55     </div>
56         {% endfor %}
57 </body>
58 </html>

py代码

 1 @app.route('/usercenter/<user_id>')
 2 @loginFirst
 3 def usercenter(user_id):
 4     user = User.query.filter(Wenda.id == user_id).first()
 5     context={
 6         'username':user.username,
 7         'wenda':user.wenda,
 8         'comments':user.comments
 9     }
10     return render_template('usercenter.html',**context)

 

posted @ 2017-12-13 15:48  013洪辉  阅读(191)  评论(0编辑  收藏  举报