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.各个页面链接到个人中心