- 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
<!doctype html> "en"> . Nav_ul li{Float:left; List-Style:none; margin:10px; Border-Bottom:outset; } </style> <meta charset="UTF-8"> <meta name="Viewport"content="width=device-width, User-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="x-ua-compatible"Content="Ie=edge"> <title> Personal Center </title> class="Nav_ul"> <li role="Presentation"><a href="#"> All questions </a></li> <li role="Presentation"><a href="#"> All reviews </a></li> <li role="Presentation"><a href="#"> Personal Information </a></li> </ul> <divclass="col-md-6 Column"> <divclass="Page-header"> {% forFooinchWenda%} <divclass="Panel Panel-default"> <divclass="panel-heading"> class="Panel-title"> <a href="{{url_for (' detail ', Wenda_id=foo.id)}}"> Title: {{foo.title}}</a><br> "{{url_for (' usercenter ', user_id=foo.author_id)}}">{{foo.author.username}}</a> </div> <divclass="Panel-body"> <a href="#"> content: {{foo.detail}}</a><br> </div> <divclass="Panel-footer"> <spanclass="badge"style="margin-left:60%">{{Foo.creat_time}} release time </span> </div> </div> {% ENDFOR%} </div> </div> <divclass="col-md-6 Column"> <divclass="Page-header"> {% forFooinchComments%} <liclass="List-group-item"> <a href="{{url_for (' usercenter ', user_id=foo.author_id)}}">{{foo.author.username}}</a> <spanclass="badge Pull-right">{{foo.create_time}}</span> <p>{{foo.detail}}</p> <br> < /li> </div> {% ENDFOR%} </body> classComment (db. Model):__tablename__='Comment'ID= db. Column (db. Integer, Primary_key=true, autoincrement=True) Title= db. Column (db. String (+), nullable=False) Detail= db. Column (db. Text, nullable=False) Creat_time= db. Column (db. DateTime, default=DateTime.Now) author_id= db. Column (db. Integer, Db. ForeignKey ('user.id')) wenda_id= db. Column (db. Integer,db. ForeignKey ('wenda.id')) Wenda= Db.relationship ('Wenda', Backref=db.backref ('Comments', order_by=Creat_time.desc)) Author= Db.relationship ('User', Backref=db.backref ('Comments'))
@app. Route ('/usercenter/<user_id>') @loginFirstdefUsercenter (user_id): User= User.query.filter (Wenda.id = =user_id). First () Context={ 'username': User.username,'Wenda': User.wenda,'Comments': user.comments}returnRender_template ('usercenter.html', **context)
<a href="{{url_for (' usercenter ', User_id=foo.author.id)}}">{{ Foo.author.username}} Comments: ({{foo.comments|length}}) </a>
Comments list display and sort, personal center display