- 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
@app. Route ('/usercenter/<user_id>') @loginFirstdefUsercenter (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)
{% block main%} <divclass="Page-header"> class="Glyphicon Glyphicon-user"aria-hidden="true"></span>{{username}}<br> <small> all questions and Answers <spanclass="badge"></span></small> class="List-group"style="margin:10px"> {% forFooinchQuestion%} <liclass="List-group-item"> <spanclass="Glyphicon Glyphicon-heart-empty"aria-hidden="true"></span> <a href="#">{{foo.author.username}}</a> <spanclass="badge">{{foo.creat_time}}</span> <p>{{foo.detail}}</p> </li> {% ENDFOR%} </ul> </div> <divclass="Page-header"> class="Glyphicon Glyphicon-user"aria-hidden="true"></span>{{user}}<br> <small> all reviews <spanclass="badge"></span></small> class="List-group"style="margin:10px"> {% forFooinchComments%} <liclass="List-group-item"> <spanclass="Glyphicon Glyphicon-heart-empty"aria-hidden="true"></span> <a href="#">{{foo.author.username}}</a> <spanclass="badge">{{foo.creat_time}}</span> <p>{{foo.detail}}</p> </li> {% ENDFOR%} </ul> </div> <divclass="Page-header"> class="Glyphicon Glyphicon-user"aria-hidden="true"></span>{{User}}<br> <small> personal information <spanclass="badge"></span></small> class="List-group"style="margin:10px"> <liclass="List-group-item"> User: {{username}}</li> <liclass="List-group-item"> Ref.:</li> <liclass="List-group-item"> Nickname:</li> </ul> </div>
<divclass="Page-header"> class="badge">{{ques.creat_time}}</span></small>>class=" Lead">detail{{ques.detail}}</p> "{{url_for (' comment ')}}"Method="Post"style="..."> <divclass="Form-group"> <textarea name="new_comment"Id="new-comment" class="Form-control"Rows="3"placeholder="Write your comment"></textarea> <input type="Hidden"Name="question_id"Value="{{ques.id}}"> </div> <button type="Submit" class="btn Btn-default"> Send </button> </form> class="List-group"style="margin:10px"></ul>> <ulclass="List-group"style="..."> {% forFooinchQuestions%} <liclass="List-group-item"> <spanclass="Glyphicon glyphicon-leaf"aria-hidden="true"></span> <a href="#">{{foo.author.username}}</a> <br> <a href="{{url_for (' detail ', Question_id=foo.id)}}">{{Foo.title}}</a> <spanclass="badge">{{foo.creat_time}}</span> <p style="...">{{Foo.detail}}</p> </li> {% ENDFOR%} </ul>
Comments list display and sort, personal center display