- 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
Usercenter.html
{% extends ' base.html '%}{% block title%} Personal Center {% Endblock%}{% block head%}<Linkrel= "stylesheet"href= "{{url_for (' static ', filename= ' Css/usercenter.css ')}}"type= "Text/css">{% endblock%}{% block main%}<BodyID= "Mybody"> <Divclass= "Total"> <Divclass= "Page-header"style= "Text-align:left"> <H3style= "font-family: italics; color: #c879ff;"><spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span>{{username}}<BR> <Small>All Questions > Answers<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="#"style= "font-family: Young circle; Color:cornflowerblue">Reader: {{foo.author.username}}</a><BR> <spanclass= "badge"style= "font-family: Young circle; Color:cornflowerblue">Release time: {{foo.creat_time}}</span><BR> <Pstyle= "font-family: Young circle; color: #002D54;">{{Foo.detail}}</P> </Li>{% endfor%}</ul> </Div> <Divclass= "Page-header"style= "Text-align:left"> <H3style= "font-family: italics; color: #c879ff;"><spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span>{{User}}<BR> <Small>All reviews ><spanclass= "badge"></span></Small> </H3> <ulclass= "List-group">{% for Foo in comments%}<Liclass= "List-group-item"> <spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span> <ahref="#"style= "font-family: Young circle; Color:cornflowerblue">Reader: {{foo.author.username}}</a><BR> <spanclass= "badge"style= "font-family: Young circle; Color:cornflowerblue">Release time: {{foo.creat_time}}</span><BR> <Pstyle= "font-family: Young circle; color: #002D54;">{{Foo.detail}}</P> </Li>{% endfor%}</ul> </Div> <Divclass= "Page-header"style= "Text-align:left"> <H3style= "font-family: italics; color: #c879ff;"><spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span>{{User}}<BR> <Small>Personal Information ><spanclass= "badge"></span></Small> </H3> <ulclass= "List-group"style= "font-family: Young circle; color: #002D54;"> <Liclass= "List-group-item">User: {{username}}</Li> <Liclass= "List-group-item">Number:</Li> <Liclass= "List-group-item">Nickname:</Li> <Liclass= "List-group-item">Article article:</Li> </ul> </Div> </Div> </Body> </HTML>{% Endblock%}
Detail.html:
<href= "{{url_for (' usercenter ', user_id = Foo.author.id)}}" style = "font-family: italic; color: #c879ff; text-align:left">{{foo.author.username}
Index.html:
<href= "{{url_for (' usercenter ', user_id = foo.author_id)}}">{{ Foo.author.username}} Comments ({{foo.comments|length}})</a>
Python:
@app. Route ('/usercenter/<user_id>') @loginFirstdefUsercenter (user_id): User=user.query.filter (user.id==user_id). First () Mycontext={ 'username': User.username,'Questions': User.question,'Comments': user.comments,}returnRender_template ('usercenter.html', **mycontext)
Comments list display and sort, personal center display