- Show All comments
{% for Foo in ques.comments%}
- All comments Sorted
Uquestion = db.relationship (' Question ', backref=db.backref (' comments ', order_by=creat_time.desc))
- Show number of comment bars
{{Ques.comments|length}}
- Complete the Personal center
1. Personal Center page layout (HTML files and corresponding style files)
<Divclass= "List-container"> <Divclass= "Wenda"> <H3>{#<spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span>#}{{username1}}<BR><Small>All questions and answers:</Small></H3> <ulclass= "News-list">{% for Foo in questions%}<Listyle= "padding-left:0px; padding-right:10px; Box-shadow:rgba (0, 0, 0, 0.5) 0px 0px 0px 0px;"> <spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span> <ahref="#">{{Foo.author.username}}</a> <spanclass= "Badgs">{{Foo.creat_time}}</span> <BR> <ahref=" #">{{Foo.title}}</a> <P>{{Foo.detail}}</P> </Li>{% endfor%}</ul> </Div> <Divclass= "Pinlun"> <H3>{#<spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span>#}{{username1}}<BR><Small>All comments:</Small></H3> <ulclass= "News-list">{% for Foo in comments%}<Listyle= "padding-left:0px; padding-right:10px; Box-shadow:rgba (0, 0, 0, 0.5) 0px 0px 0px 0px;"> <spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true" ></span> <ahref="#">{{Foo.author.username}}</a> <BR> <spanclass= "Badgs">{{Foo.creat_time}}</span> <P>{{Foo.detail}}</P> </Li>{% endfor%}</ul> </Div> <Divclass= "per"> <H3><spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span>{{username1}}<BR><Small>Personal information:</Small></H3> <ulclass= "News-list"> {#<Listyle= "padding-left:0px; padding-right:10px; Box-shadow:rgba (0, 0, 0, 0.5) 0px 0px 0px 0px;">#} <Liclass= "List-group-item">User: {{username}}</Li> <Liclass= "List-group-item">Number: {{user_id}}</Li> <Liclass= "List-group-item">Nickname:</Li> <Liclass= "List-group-item">Article number:</Li> </ul> </Div></Div>
2. Define the View function Def usercenter (user_id):
#User Center@app. Route ('/usercenter/<user_id>/') @loginFirstdefUsercenter (user_id): User= User.query.filter (user.id==user_id). First () Context={ 'username1': User.username,'Questions': User.question,'Comments': user.comments}returnRender_template ('usercenter.html', **context)
3. Passing parameters to the front-end page
4. The page displays the corresponding data
All questions and Answers released
All comments Posted
Personal information
5. Each page links to a personal center
Comments list display and sort, personal center display