- 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)
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 ' myweb.html '%}{% block title%} Personal Center {% endblock%}{% block main%}<Divclass= "Page-header"> <H3><spanclass= "Glyphicon glyphicon-user"Aria-hidden= "true"></span>{{username}}<BR> <Small>All Questions > Answers<spanclass= "badge"></span> </Small></H3> <ulclass= "List-group"style="">{% for Foo in user.question%}<binclass= "List-group-item"> <spanclass= "Glyphicon glyphicon-heart-empty"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>{{User}}<BR> <Small>Personal Information ><spanclass= "badge"></span> </Small></H3> <ulclass= "List-group"style="">{% for Foo in user.comments%}<Liclass= "List-group-item"> <spanclass= "Glyphicon glyphicon-heart-empty"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>{{User}}<BR> <Small>Personal Information ><spanclass= "badge"></span> </Small></H3> <ulclass= "List-group"style=""> <Liclass= "List-group-item">User: {{username}}</Li> <Liclass= "List-group-item">Title:</Li> </ul></Div>{% Endblock%}
@app. Route ('/usercenter/<user_id>') @loginFirstdef usercenter (user_id): user = User.query.filter (user.id = = user_id). First () context = { ' username ': user.username, ' Fabu ': User.fabu, ' comments ': user.comments } return render_template (' usercenter.html ', **context)
Comments list display and sort, personal center display