- 显示所有评论
{% for foo in ques.comments %} - 所有评论排序
uquestion = db.relationship(‘Question‘, backref=db.backref(‘comments‘, order_by=creat_time.desc)) - 显示评论条数
{{ ques.comments|length }} - 完成个人中心
1.个人中心的页面布局(html文件及相应的样式文件)
<div class="list-container"> <div class="wenda"> <h3>{#<span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>#}{{ username1 }}<br><small>全部问答:</small></h3> <ul class="news-list"> {% for foo in questions %} <li style="padding-left: 0px; padding-right: 10px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 0px 0px;"> <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span> <a href="#">{{ foo.author.username }}</a> <span class="badgs">{{ foo.creat_time }}</span> <br> <a href=" #">{{ foo.title }}</a> <p>{{ foo.detail}}</p> </li> {% endfor %} </ul> </div> <div class="pinlun"> <h3>{#<span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>#}{{ username1 }}<br><small>全部评论:</small></h3> <ul class="news-list"> {% for foo in comments %} <li style="padding-left: 0px; padding-right: 10px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 0px 0px;"> <span class="glyphicon glyphicon-leaf" aria-hidden="true" ></span> <a href="#">{{ foo.author.username }}</a> <br> <span class="badgs">{{ foo.creat_time }}</span> <p>{{ foo.detail}}</p> </li> {% endfor %} </ul> </div> <div class="per"> <h3><span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>{{ username1 }}<br><small>个人信息:</small></h3> <ul class="news-list"> {#<li style="padding-left: 0px; padding-right: 10px; box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 0px 0px;">#} <li class="list-group-item">用户:{{ username }}</li> <li class="list-group-item">编号:{{ user_id }}</li> <li class="list-group-item">昵称:</li> <li class="list-group-item">文章篇数:</li> </ul> </div> </div>
2.定义视图函数def usercenter(user_id):
#用户中心 @app.route(‘/usercenter/<user_id>/‘) @loginFirst def usercenter(user_id): user = User.query.filter(User.id==user_id).first() context={ ‘username1‘:user.username, ‘questions‘:user.question, ‘comments‘:user.comments } return render_template(‘usercenter.html‘,**context)
3.向前端页面传递参数
4.页面显示相应数据
发布的全部问答
发布的全部评论
个人信息
5.各个页面链接到个人中心