- 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
<ulclass="List"> {% forFooinchQues.comments%} <liclass="Post_item"> <a href="{{url_for (' usercenter ', User_id=foo.author.id)}}" class=" Light">{{foo.author.username}}</a> <br> " -"height=" -" class="PF"Src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4066191998,32277144&fm=27&gp=0.jpg "alt=""> <pclass="Post_item">{{Foo.detail}}</p> <spanclass="Foot"> Posted in {{Foo.create_time}}</span> </li> {% ENDFOR%} </ul>
{% extends'base.html'%}{% block title%} Personal Center {% Endblock%}{% Block Head%}<link rel="stylesheet"Type="Text/css"href="{{url_for (' static ', filename= ' Css/detail.css ')}}">{% Endblock%}{% Block main%} <divclass="Post"> class="title"><span>{{username}}<br><small> all answers </small></span>class="List"> {% forFooinchQuestions%} <liclass="Post_item"> <a href="#" class=" Light">{{foo.author.username}}</a> " -"height=" -" class="PF"Src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4066191998,32277144&fm=27&gp=0.jpg "alt=""> <pclass="Post_item">{{Foo.detail}}</p> <spanclass="Foot"> Posted in {{Foo.create_time}}</span> </li> {% ENDFOR%} </ul> </div> <divclass="Post"> class="title"><span></span>{{User}}<br><small> All reviews <span></span></small>class="List"> {% forFooinchComments%} <liclass="Post_item"> <a href="#" class=" Light">{{foo.author.username}}</a> " -"height=" -" class="PF"Src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4066191998,32277144&fm=27&gp=0.jpg"alt=""> <pclass="Post_item">{{Foo.detail}}</p> <spanclass="Foot"> Posted in {{Foo.create_time}}</span> </li> {% ENDFOR%} </ul> </div> <divclass="Post"> class="title"><span></span>{{User}}<br><small> Personal information <span></span></small>class="Post_item"> User: {{username}}</li> <liclass="Post_item"> Ref.:</li> <liclass="Post_item"> Nickname:</li> <liclass="Post_item"> article number:</li> </ul> </div>{% Endblock%
Copy Code @app.route ('/usercenter/<user_id>') @loginFirstdef Usercenter (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)
Comment List display and sort, personal center display