Comments list display and sort, personal center display

Source: Internet
Author: User

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

<ulclass= "List-group"style= "margin:10px">{% for Foo in questions.comments%}<binclass= "List-group-item">         <spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span>         <ahref="#">{{Foo.author.username}}</a>         <spanclass= "badge">{{Foo.creat_time}}</span>         <Pstyle="...">{{Foo.detail}}</P>    </Li>{% endfor%}</ul>

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

classComment (db. Model):__tablename__='Comment'ID= db. Column (db. Integer, Primary_key=true, autoincrement=True) author_id= db. Column (db. Integer,db. ForeignKey ('user.id')) question_id= db. Column (db. Integer,db. ForeignKey ('question.id')) Creat_time= db. Column (db. datetime,default=datetime.now) Detail= db. Column (db. text,nullable=False) Question= Db.relationship ('Question', Backref = Db.backref ('Comments', order_by=Creat_time.desc)) Author= Db.relationship ('User', Backref = Db.backref ('Comments'))

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

< h4 > Comments ({{questions.comments|length}})</h4>

4. Complete the Personal center

A. The page layout of the personal Center (HTML files and corresponding style files)

B. Defining the View function Def usercenter (user_id):

C. Passing parameters to a front-end page

D. The page displays the corresponding data

All questions and Answers released

All comments Posted

Personal information

E. Linking individual pages to a personal hub

{% extends ' base.html '%}{% block title%} Personal Center {% Endblock%}{% block main%}<Divclass= "Page-header">        <H3><spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span>{{username}}<BR><Small>All questions<spanclass= "Badge>"></span></Small></H3>        <ulclass= "List-group">{% for Foo in questions%}<Liclass= "List-group-item">                    <spanclass= "Glyphicon glyphicon-leaf"Aria-hidden= "true"></span>                    <ahref="#">{{Foo.author.username}}</a>                    <spanclass= "badge">{{Foo.creat_time}}</span>                    <Pstyle="...">{{Foo.detail}}</P>                </Li>{% endfor%}</ul>    </Div>    <Divclass= "Page-header">       <H3><spanclass= "Glyphicon glyphicon-user"Aria-hidden= "true"></span>{{username}}<BR><Small>All reviews<spanclass= "badge"></span></Small></H3>       <ulclass= "List-group">{% for Foo in comments%}<Liclass= "List-group-item">                   <spanclass= "Glyphicon glyphicon-heart-empty"Aria-hidden= "true"></span>                   <ahref="#">{{Foo.author.username}}</a>                   <spanclass= "badge">{{Foo.create_time}}</span>                   <Pstyle="...">{{Foo.detail}}</P>               </Li>{% endfor%}</ul>   </Div>     <Divclass= "Page-header">        <H3><spanclass= "Glyphicon glyphicon-user"Aria-hidden= "true"></span>{{User}}<BR><Small>Personal information<spanclass= "Badge>"></span> </Small> </H3>        <ulclass= "List-group">            <Liclass= "List-group-item">User: {{username}}</Li>            <Liclass= "List-group-item">Number: {{id}}</Li>            <Liclass= "List-group-item">Nickname: {{Nickname}}</Li>        </ul>     </Div>{% Endblock%}

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.