1. Show All comments
{% for Foo in ques.comments%}
<ulclass="Comment"> {% forFooinchQuestion.comments%} <spanclass="icon"aria-hidden="true">".. /static/images/icon.jpg"></span> <a href="{{url_for (' self ', user_id=foo.author_id)}}" class="name">{{foo.author.username}}</a> <spanclass="Badge2">{{foo.creattime}}</span> <br> <pclass="Neirong">{{Foo.detail}}</p> {% ENDFOR%} </ul>
2. Sort all comments
Uquestion = db.relationship (' Question ', backref=db.backref (' comments ', order_by=creat_time.desc))
Question = Db.relationship ('question', Backref=db.backref ('comments ', Order_by=create_time.desc))
3. Show number of comment bars
{{Ques.comments|length}}
class="tcomment"> Comments: ({{ques.comments|length}}) </span>
4. 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
@app. Route ('/usercenter/<user_id>') @loginFirstdef Usercenter (user_id): User= User.query.filter (User.ID = =user_id). First () Context={ # 'username': User.username, #'question': user.questions, #'Comments'; user.comments'User': User}returnRender_template ('usercenter.html', **context)
{% extends'base.html'%}{% Block Title%} User Center {% Endblock%}{% Block Head%}<link rel="stylesheet"href="{{url_for (' static ', filename= ' Css/usercenter.css ')}}"Type="Text/css">{% Endblock%}{% Block main%} <divclass="Big"><divclass="content"> class="Glyphicon-leaf"aria-hidden="true"></span>"Qu"Src="{{url_for (' static ', filename= ' images/question.jpg ')}}">{{User.username}}<br><small> all questions and answers: </small>class="List-group"> {% forFooinchUser.question%} <liclass="List-group-item"> <spanclass="Glyphicon-leaf"aria-hidden="true"></span> "Qu"Src="{{url_for (' static ', filename= ' images/question.jpg ')}}"> <a href ="">{{foo.author.username}}</a> <spanclass="badge"> Comment Time: {{foo.create_time}}</span> <p style="Text-align:left">{{Foo.detail}}</p></li> {% ENDFOR%} </ul></div><divclass="content"> class="Glyphicon-leaf"aria-hidden="true"></span> "Qu"Src="{{url_for (' static ', filename= ' images/question.jpg ')}}">{{User.username}}<br><small> All reviews: </small>class="List-group"> {% forFooinchUser.comments%} <liclass="List-group-item"> <spanclass="Glyphicon-leaf"aria-hidden="true"></span> "Qu"Src="{{url_for (' static ', filename= ' images/question.jpg ')}}"><a href ="">{{foo.author.username}}</a> <spanclass="badge"> Comment Time: {{foo.create_time}}</span> <p style="Text-align:left">{{Foo.detail}}</p></li> {% ENDFOR%} </ul></div><divclass="content"> class="Glyphicon-leaf"aria-hidden="true"></span> "Qu"Src="{{url_for (' static ', filename= ' images/question.jpg ')}}">{{User.username}}<br> <small> Personal Information:</small>class="List-group"> <liclass="List-group-item"> User: {{user.username}}</li> <liclass="List-group-item"> Number: {{user.id}}</li> <liclass="List-group-item"> Nickname: {{user.nickname}}</li> <liclass="List-group-item"> Article number: {{user.question|length}}</li> </ul></div> </div>{% Endblock%}
Comment List display and sort, personal center display