- Show All comments
{% for Foo in ques.comments%}
<ulclass= "List-group">{% for Foo in ques.comments%}<Liclass= "List-group-item"> <spanclass= "Glyphion-heart-empty"Aria-hidden= "true"></span> ?<ahref= "{{url_for (' usercenter ', user_id=foo.author_id)}}">{{Foo.author.username}}</a> <spanclass= "badge">{{Foo.creat_time}}</span> <Pclass= "Comdetail">{{Foo.detail}}</P> </Li>{% endfor%}</ul>
- All comments Sorted
Uquestion = db.relationship (' Question ', backref=db.backref (' comments ', order_by=creat_time.desc))
Question=db.relationship ('question', Backref=db.backref ('comments ', Order_by=creat_time.desc))
- Show number of comment bars
{{Ques.comments|length}}
< h4 > Comments: ({{ques.comments|length}})</h4>
- 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.question,'Comments': user.comments}returnRender_template ('usercenter.html', **context)
{% 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%}<Body> <Divclass= "D1"><H3>All questions</H3>{% for foo in questions%}<HR> <Tableclass= "Table"> <TR><TD> <P>Title: {{foo.question}}</P> <P>Content: {{Foo.questiondetail}}</P></TD></TR> </Table> <imgclass= "Unicorn"src= "{{url_for (' static ', filename= ' images/bulbon.jpg ')}}"width= "20px"><ahref= "{{url_for (' usercenter ', user_id=foo.author_id)}}"class= "Name">{{Foo.author.username}} {{foo.creat_time}}<BR></a>{% endfor%}<HR><HR> <H3>All reviews</H3>{% for foo in comments%}<HR> <Tableclass= "Table" > <TR><TD><spanclass= "Time" >{{Foo.creat_time}}</span><BR> <P>{{Foo.detail}}</P></TD></TR> </Table> <ahref= "{{url_for (' usercenter ', user_id=foo.author_id)}}"class= "Name">{{Foo.author.username}}</a>{% endfor%}<HR><HR> <H3>Personal information</H3><HR> <Tableclass= "Table" > <TR><TD> <Listyle= "List-style:none">User: {{username}}</Li> <Listyle= "List-style:none">ID Number:</Li></TD></TR> </Table> </Div> </Body>{% Endblock%}
Comments list display and sort, personal center display