- 显示所有评论{% 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.各个页面链接到个人中心
评论:({ { quest.comment|length }})
{% for foo in comments %} {% 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'))
全部问答
{% for foo in questions %}标题:{ { foo.title}}{% endfor %}内容:{ { foo.detail}} { { foo.creat_time }}
全部评论
{% for foo in comments %}{ {foo.detail}}
{foo.create_time}{% endfor %}{ {username.username}}
Panel content