Comments list display and sort, personal center display

Source: Internet
Author: User

    1. Show All comments
      {% for Foo in ques.comments%}

    2. All comments Sorted
      Uquestion = db.relationship (' Question ', backref=db.backref (' comments ', order_by=creat_time.desc))

    3. Show number of comment bars
      {{Ques.comments|length}}

    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

<!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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.