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

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

时间:2017-12-13 02:11:30      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:turn   styles   页面布局   play   hid   int   stat   text   efault   

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

 <div>

            <h4>评论:({{ sen.comments|length }})</h4>
            {% for foo in comment %}
                <ul style="padding-left: 0px;margin-bottom: 0px;">
                    <li class="list-group-item" style="width: 900px">
                        <a href="{{ url_for(‘usercenter‘,user_id=foo.author.id) }}">{{ foo.author.username }}</a>
                        <span class="badge">评论时间:{{ foo.creat_time }}</span>
                        <p>{{ foo.detail }}</p>
                    </li>
                </ul>

            {% endfor %}

        </div>

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

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‘))
    sent_id = db.Column(db.Integer, db.ForeignKey(‘sent.id‘))
    creat_time = db.Column(db.DateTime, default=datetime.now)
    detail = db.Column(db.TEXT, nullable=False)
    sent = db.relationship(‘Sent‘, backref=db.backref(‘comments‘,order_by=creat_time.desc))
    author = db.relationship(‘User‘, backref=db.backref(‘comments‘))

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

   <h4>评论:({{ sen.comments|length }})</h4>

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

.页面显示相应数据

发布的全部问答

发布的全部评论

个人信息

html

{% extends ‘index.html‘ %}
<title>
    {% block title %}
        个人中心
    {% endblock %}
</title>
{% block head %}
 <link rel="stylesheet" type="text/css" href="{{ url_for(‘static‘,filename=‘css/geren.css‘) }}">
{% endblock %}
{#<link rel="stylesheet" href="../static/css/geren.css">#}

{% block body %}
<div class="all have-img">

    <div>
        {% for foo in username %}
        <h4>用户名:{{ foo.author.username }}
            <br>
            <small>全部问答</small>
        </h4>
        <ul style="padding-left: 0px;margin-bottom: 0px;">
            <li class="list-group-item" style="width: 900px">
                <a href="">{{ foo.author.username }}</a>
                <span class="badge">评论时间:{{ foo.creat_time }}</span>
                <p>{{ foo.detail }}</p>
            </li>
        </ul>
    </div>
    <hr>

    <div>
        {% for foo in comment %}
        <h4>用户名:{{ foo.author.username }}
            <br>
            <small>全部评论</small>
        </h4>
        <ul style="padding-left: 0px;margin-bottom: 0px;">
            <li class="list-group-item" style="width: 900px">
                <a href="#">{{ foo.author.username }}</a>
                <span class="badge">评论时间:{{ foo.creat_time }}</span>
                <p>{{ foo.detail }}</p>
            </li>
        </ul>

    </div>
    <hr>

    <div>
        <h4>{{ user }}
            <br>
            <small>用户资料</small>
        </h4>

        <ul style="padding-left: 0px;margin-bottom: 0px;">
            <li class="list-group-item" style="width: 900px">用户:{{ username }}</li>
            <li class="list-group-item" style="width: 900px">编号:</li>
            <li class="list-group-item" style="width: 900px">昵称:</li>
        </ul>
    </div>

</div>
{% endblock %}

css

.all {
    margin-left: 300px;
    margin-right: auto;
    width: 300px;
}

.have-img {
    list-style-type: none;
}

.list-group-item {
    position: relative;
    display: block;
    padding: 10px 15px;
    margin-bottom: -1px;
    background-color: #fff;
    border: 1px solid #ddd;
}

.badge {
    display: inline-block;
    min-width: 10px;
    padding: 3px 7px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    background-color: #777;
    border-radius: 10px;
    margin-left: 650px;
}

hr {
    width: 930px;
    color: #fcf3f3;
}

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

@app.route(‘/usercenter/<user_id>‘)
@loginFirst
def usercenter(user_id):
    user=User.query.filter(User.id==user_id).first()
    context={
        ‘username‘:user.username,
        ‘sent‘:user.sent,
        ‘comments‘:user.comments
    }
    return render_template(‘geren.html‘,**context)

3.向前端页面传递参数

<input type="hidden" name="sent_id" id="sent_id" value="{{ sen.id }}">

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

#首页用户名链接到个人中心
<a class="nickname" target="_blank" href="{{ url_for(‘usercenter‘,user_id=foo.author_id) }}">{{ foo.author.username }}</a>


#详情用户名连接到个人中心
  <a href="{{ url_for(‘usercenter‘,user_id=foo.author.id) }}">{{ foo.author.username }}</a>

 

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

标签:turn   styles   页面布局   play   hid   int   stat   text   efault   

原文地址:http://www.cnblogs.com/pys965085265/p/8030504.html

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