- 显示所有评论
{% for foo in ques.comments %} - 所有评论排序
uquestion = db.relationship(‘Question‘, backref=db.backref(‘comments‘, order_by=creat_time.desc)) - 显示评论条数
{{ ques.comments|length }} - 完成个人中心
1.个人中心的页面布局(html文件及相应的样式文件)
2.定义视图函数def usercenter(user_id):
3.向前端页面传递参数
4.页面显示相应数据
发布的全部问答
发布的全部评论
个人信息
5.各个页面链接到个人中心
<h4>评论:({{ quest.comment|length }})</h4> {% for foo in comments %} <div class="list-group"> <a href="" class="list-group-item active">作者:{{ foo.author.username}}</a> <div class="list-group-item"> <a href="" class="list-group-item-heading"> </a> <p class="list-group-item-text"> {{foo.detail}} </p> </div> <div class="list-group-item"> <span class="badge">发布时间:{{foo.creat_time}}</span> 发布时间 </div> </div> {% endfor %}
class Comment(db.Model): __tablename__ = ‘comment‘ id = db.Column(db.Integer, primary_key=True, autoincrement=True) author_id = db.Column(db.Integer, db.ForeignKey(‘user.id‘)) question_id = db.Column(db.Integer, db.ForeignKey(‘question.id‘)) creat_time = db.Column(db.DateTime, default=datetime.now) detail = db.Column(db.Text, nullable=False) question = db.relationship(‘Ques‘, backref=db.backref(‘comment‘, order_by=creat_time.desc)) author = db.relationship(‘User‘, backref=db.backref(‘comment‘))
<div class="container"> <div class="row clearfix"> <div class="col-md-2 column"> <h2>全部问答</h2> <div class="list-group"> {% for foo in questions %} <div class="list-group-item"> 标题:{{ foo.title}} </div> <div class="list-group-item"> <p class="list-group-item-text"> 内容:{{ foo.detail}} <span class="badge">{{ foo.creat_time }}</span> </p> </div> {% endfor %} </div> </div> <div class="col-md-6 column"> <h2>全部评论</h2> <div class="panel panel-default"> {% for foo in comments %} <div class="panel-heading"> <h3 class="panel-title"> {{foo.detail}} </h3> </div> <div class="panel-body"> {foo.create_time} </div> <div class="panel-footer"> Panel footer </div> {% endfor %} </div> </div> <div class="col-md-4 column"> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title"> {{username.username}} </h3> </div> <div class="panel-body"> Panel content </div> <div class="panel-footer"> Panel footer </div> </div> </div> </div> </div>