- 显示所有评论
{% for foo in ques.comments %}
<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 %}
- 所有评论排序
uquestion = db.relationship('Question', backref=db.backref('comments', order_by=creat_time.desc))
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'))
- 显示评论条数
{{ ques.comments|length }} - 完成个人中心
1.个人中心的页面布局(html文件及相应的样式文件)
2.定义视图函数def usercenter(user_id):
3.向前端页面传递参数
4.页面显示相应数据
发布的全部问答
发布的全部评论
个人信息
5.各个页面链接到个人中心