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

  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.頁面顯示相應數據python

發佈的所有問答app

發佈的所有評論函數

我的信息佈局

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

 usercenter.htmlspa

{% extends'base.html' %}
{% block title %}
    我的中心
{% endblock %}
{% block head %}
<link rel="stylesheet" href="{{ url_for('static',filename='css/usercenter.css') }}" type="text/css">
{% endblock %}
{% block main %}
    <body id="myBody">
    <div class="total">
    <div class="page-header" style="text-align: left">
        <h3 style="font-family: 楷體;color: #c879ff;"><span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>{{ username }}<br>
            <small>所有問答><span class="badge"></span></small>
        </h3>
        <ul class="list-group">
            {% for foo in questions %}
                <li class="list-group-item">
                    <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>
                    <a href="#" style="font-family: 幼圓;color: cornflowerblue">讀者:{{ foo.author.username }}</a><br>
                    <span class="badge" style="font-family: 幼圓;color: cornflowerblue">發佈時間:{{ foo.creat_time }}</span><br>
                    <p style="font-family: 幼圓;color: #002D54;">{{ foo.detail }}</p>
                </li>
            {% endfor %}
        </ul>

    </div>
    <div class="page-header" style="text-align: left">
        <h3 style="font-family: 楷體;color: #c879ff;"><span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>{{ user }}<br>
            <small>所有評論><span class="badge"></span></small>
        </h3>
        <ul class="list-group">
            {% for foo in comments %}
                <li class="list-group-item">
                    <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>
                    <a href="#" style="font-family: 幼圓;color: cornflowerblue">讀者:{{ foo.author.username }}</a><br>
                    <span class="badge" style="font-family: 幼圓;color: cornflowerblue">發佈時間:{{ foo.creat_time }}</span><br>
                    <p style="font-family: 幼圓;color: #002D54;">{{ foo.detail }}</p>
                </li>
            {% endfor %}
        </ul>
    </div>
    <div class="page-header" style="text-align: left">
        <h3 style="font-family: 楷體;color: #c879ff;"><span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>{{ user }}<br>
            <small>我的信息><span class="badge"></span></small>
        </h3>
        <ul class="list-group" style="font-family: 幼圓;color: #002D54;">
            <li class="list-group-item">用戶:{{ username }}</li>
            <li class="list-group-item">編號:</li>
            <li class="list-group-item">暱稱:</li>
            <li class="list-group-item">文章篇:</li>
        </ul>
    </div>
    </div>
    </body>
    </html>
{% endblock %}

detail.html:code

<a href="{{ url_for('usercenter',user_id = foo.author.id) }}" style="font-family: 楷體;color: #c879ff;text-align: left">做者:{{ foo.author.username }

index.html:

<a href="{{ url_for('usercenter',user_id = foo.author_id) }}">{{ foo.author.username }}評論({{ foo.comments|length }})</a>

python:

@app.route('/usercenter/<user_id>')
@loginFirst
def usercenter(user_id):
    user=User.query.filter(User.id==user_id).first()
    mycontext={
        'username':user.username,
        'questions':user.question,
        'comments':user.comments,
    }
    return render_template('usercenter.html',**mycontext)

相關文章
相關標籤/搜索