1. Show All comments
{% for Foo in ques.comments%}
<ulclass= "List-group"style= "margin:10px">{% for Foo in questions.comments%}<binclass= "List-group-item"> <spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span> <ahref="#">{{Foo.author.username}}</a> <spanclass= "badge">{{Foo.creat_time}}</span> <Pstyle="...">{{Foo.detail}}</P> </Li>{% endfor%}</ul>
2. Sort all comments
Uquestion = db.relationship (' Question ', backref=db.backref (' comments ', order_by=creat_time.desc))
classComment (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 ('Question', Backref = Db.backref ('Comments', order_by=Creat_time.desc)) Author= Db.relationship ('User', Backref = Db.backref ('Comments'))
3. Show number of comment bars
{{Ques.comments|length}}
< h4 > Comments ({{questions.comments|length}})</h4>
4. Complete the Personal center
A. The page layout of the personal Center (HTML files and corresponding style files)
B. Defining the View function Def usercenter (user_id):
C. Passing parameters to a front-end page
D. The page displays the corresponding data
All questions and Answers released
All comments Posted
Personal information
E. Linking individual pages to a personal hub
{% extends ' base.html '%}{% block title%} Personal Center {% Endblock%}{% block main%}<Divclass= "Page-header"> <H3><spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span>{{username}}<BR><Small>All questions<spanclass= "Badge>"></span></Small></H3> <ulclass= "List-group">{% for Foo in questions%}<Liclass= "List-group-item"> <spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span> <ahref="#">{{Foo.author.username}}</a> <spanclass= "badge">{{Foo.creat_time}}</span> <Pstyle="...">{{Foo.detail}}</P> </Li>{% endfor%}</ul> </Div> <Divclass= "Page-header"> <H3><spanclass= "Glyphicon glyphicon-user"Aria-hidden= "true"></span>{{username}}<BR><Small>All reviews<spanclass= "badge"></span></Small></H3> <ulclass= "List-group">{% for Foo in comments%}<Liclass= "List-group-item"> <spanclass= "Glyphicon glyphicon-heart-empty"Aria-hidden= "true"></span> <ahref="#">{{Foo.author.username}}</a> <spanclass= "badge">{{Foo.create_time}}</span> <Pstyle="...">{{Foo.detail}}</P> </Li>{% endfor%}</ul> </Div> <Divclass= "Page-header"> <H3><spanclass= "Glyphicon glyphicon-user"Aria-hidden= "true"></span>{{User}}<BR><Small>Personal information<spanclass= "Badge>"></span> </Small> </H3> <ulclass= "List-group"> <Liclass= "List-group-item">User: {{username}}</Li> <Liclass= "List-group-item">Number: {{id}}</Li> <Liclass= "List-group-item">Nickname: {{Nickname}}</Li> </ul> </Div>{% Endblock%}
Comments list display and sort, personal center display