码迷,mamicode.com
首页 > 编程语言 > 详细

评论列表显示及排序,个人中心显示

时间:2017-12-14 04:25:28      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:primary   body   integer   ane   问答   des   esc   clear   int   

  1. 显示所有评论
    {% for foo in ques.comments %}

  2. 所有评论排序
    uquestion = db.relationship(‘Question‘, backref=db.backref(‘comments‘, order_by=creat_time.desc))

  3. 显示评论条数
    {{ ques.comments|length }}

  4. 完成个人中心

1.个人中心的页面布局(html文件及相应的样式文件)

2.定义视图函数def usercenter(user_id):

3.向前端页面传递参数

4.页面显示相应数据

发布的全部问答

发布的全部评论

个人信息

5.各个页面链接到个人中心

 

<h4>评论:({{ quest.comment|length }})</h4>
     {% for foo in comments %}
            <div class="list-group">
                 <a href="" class="list-group-item active">作者:{{ foo.author.username}}</a>

                <div class="list-group-item">
                    <a href="" class="list-group-item-heading">

                    </a>
                    <p class="list-group-item-text">
                        {{foo.detail}}
                    </p>
                </div>
                <div class="list-group-item">
                     <span class="badge">发布时间:{{foo.creat_time}}</span> 发布时间
                </div>
        </div>
             {% endfor %}
class Comment(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(Ques, backref=db.backref(comment, order_by=creat_time.desc))
    author = db.relationship(User, backref=db.backref(comment))
<div class="container">
    <div class="row clearfix">
        <div class="col-md-2 column">
        <h2>全部问答</h2>
            <div class="list-group">
                {% for foo in questions %}
                <div class="list-group-item">
                    标题:{{ foo.title}}
                </div>
                <div class="list-group-item">
                    <p class="list-group-item-text">
                        内容:{{ foo.detail}} <span class="badge">{{ foo.creat_time }}</span>
                    </p>

                </div>

                {% endfor %}
            </div>

        </div>
        <div class="col-md-6 column">
            <h2>全部评论</h2>
            <div class="panel panel-default">
                                 {% for foo in comments %}
                <div class="panel-heading">
                    <h3 class="panel-title">
                        {{foo.detail}}
                    </h3>
                </div>
                <div class="panel-body">
                    {foo.create_time}
                </div>
                <div class="panel-footer">
                    Panel footer
                </div>
                                {% endfor %}
            </div>
        </div>

        <div class="col-md-4 column">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        {{username.username}}
                    </h3>
                </div>
                <div class="panel-body">
                    Panel content
                </div>
                <div class="panel-footer">
                    Panel footer
                </div>
            </div>
        </div>
    </div>
</div>

 

评论列表显示及排序,个人中心显示

标签:primary   body   integer   ane   问答   des   esc   clear   int   

原文地址:http://www.cnblogs.com/xy123ing/p/8034986.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!