評論列表顯示及排序,我的中心顯示

  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文件及相應的樣式文件)css

2.定義視圖函數def usercenter(user_id):html

3.向前端頁面傳遞參數前端

4.頁面顯示相應數據bootstrap

發佈的所有問答app

發佈的所有評論函數

我的信息佈局

5.各個頁面連接到我的中心post

@app.route('/usercenter/<user_id>')
@loginFirst
def usercenter(user_id):
    user=User.query.filter(User.id==user_id).first()
    context={
        'username':user.username,
        'question':user.question,
        'comments':user.comments
    }
    return render_template('usercenter.html',**context)
{% extends 'shouye.html' %}
{% block title %}我的中心{% endblock %}
{% block head %}
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../static/css/usercenter.css">
{% endblock %}

{% block main %}
    <div class="page-header">
        <h3><span class="glyphicon glyphicon-user"  aria-hidden="true"></span>{{ username }}<br>
            <small>所有問答<span class="s1"></span></small>
        </h3>
        <ul class="list-group" style="margin: 10px">
            {% for foo in question %}
                <li class="list-group-item">
                    <span class="glyphicon glyphicon-heart-empty" aria-hidden="true"></span>
                    <a href="#">{{ foo.author.username }}</a>
                    <span class="s2">{{ foo.create_time }}</span>
                    <p>{{ foo.detail }}</p>
                </li>
            {% endfor %}
        </ul>
    </div>

    <div class="page-header">
        <h3><span class="glyphicon glyphicon-user" aria-hidden="true"></span>{{ user }}<br>
            <small>所有評論<span class="s1"></span></small>
        </h3>
        <ul class="list-group" style="margin: 10px">
            {% for foo in comments %}
                <li class="list-group-item">
                    <span class="glyphicon glyphicon-heart-empty" aria-hidden="true"></span>
                    <a href="#">{{ foo.author.username }}</a>
                    <span class="s2">{{ foo.create_time }}</span>
                    <p>{{ foo.detail }}</p>
                </li>
            {% endfor %}
        </ul>
    </div>

    <div class="page-header">
        <h3><span class="glyphicon glyphicon-user" aria-hidden="true"></span>{{ user }}<br>
            <small>我的信息<span class="s1"></span></small>
        </h3>
        <ul class="list-group" style="margin: 10px">
            <li class="list-group-item">用戶:{{ username }}</li>
            <li class="list-group-item">編號:</li>
            <li class="list-group-item">暱稱:</li>
        </ul>
    </div>
{% endblock %}
   {% for foo in ques.comments %}
                <li class="post_item">
                    <a href="{{ url_for('usercenter',user_id=foo.author.id) }}" class="light">{{foo.author.username }}</a><br>
                    <p class="post_item">{{ foo.detail }}</p>
                    <span class="foot">發佈於  {{ foo.create_time }}</span>
                </li>
                <hr>
            {% endfor %}
        </ul>
相關文章
相關標籤/搜索