- 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}}
@app. Route ('/usercenter/<user_id>') @logdefUsercenter (user_id): User=user.query.filter (user.id==user_id). First () Context={ 'username': User.username,'Questions': User.questions,'Comments': user.comments}returnRender_template ('usercenter.html', **context)
- Complete the Personal center
<h4>Comment: ({{ques.comments|length}})</h4><BR> <ulclass= "List1">{% for Foo in ques.comments%}<Liclass= "List2"> <imgstyle= "width:30px"src= "{{url_for (' static ', Filename= '). /static/images/friends.jpg ')}} " > <ahref= "{{url_for (' all ', user_id=foo.author_id)}}">{{Foo.author.username}}</a> <spanclass= "badge">{{Foo.creat_time}}</span><BR> <Pclass= "Pinglun">Comment: {{foo.detail}}</P><BR> </Li>{% endfor%}</ul>
1. Personal Center page layout (HTML files and corresponding style files)
2. Define the View function Def usercenter (user_id):
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
{% extends ' base.html '%}{% block title%} Personal Center {% Endblock%}{% block head%}<Divclass= "Page-header"> <H3><spanclass= "Glyphicon glyphicon-user"Aria-hidden= "true"></span>{{username}}<BR><Small>All questions<spanclass= "badge"></span></Small></H3> <ulclass= "List-group"style= "Align-items:center">{% for Foo in questions%}<Liclass= "List-group-item"> <spanclass= "Glyphicon glyphicon-heart-empty"Aria-hidden= "true"></span> <ahref= "{{url_for (' usercenter ', user_id=foo.author_id)}}">{{Foo.author.username}}</a> <spanclass= "badge">{{Foo.creat_time}}</span> <Pstyle= "text-indent:18px">{{Foo.detail}}</P> </Li>{% endfor%}</ul> </Div> <Divclass= "Page-header"> <H3><spanclass= "Glyphicon glyphicon-user"Aria-hidden= "true"></span>{{User}}<BR><Small>All reviews<spanclass= "badge"></span></Small></H3> <ulclass= "List-group"style= "Align-items:center">{% for Foo in questions%}<Liclass= "List-group-item"> <spanclass= "Glyphicon glyphicon-heart-empty"Aria-hidden= "true"></span> <ahref= "{{url_for (' usercenter ', user_id=foo.author_id)}}">{{Foo.author.username}}</a> <spanclass= "badge">{{Foo.creat_time}}</span> <Pstyle= "text-indent:18px">{{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"style= "Align-items:center"> <ahref= "{{url_for (' usercenter ', user_id=foo.author_id)}}">{{Foo.author.username}}</a> <Liclass= "List-group-item">User: {{username}}</Li> <Liclass= "List-group-item">Number: {{username}}</Li> <Liclass= "List-group-item">Nickname: {{username}}</Li> <Liclass= "List-group-item">Article number: {{username}}</Li> </ul> </Div>{% Endblock%}
Comments list display and sort, personal center display