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

1.顯示全部評論html

{% for foo in ques.comments %}前端

<h3>評論區:
    ({{ ques.comments|length }})
</h3><br>


<div class="basic_box" style="padding-bottom: 50px;">
    <ul class="list-group" style="margin-bottom: 10px">
      {% for qu in ques.comments %}

            <li class="list-group-item" style="width: 800px">


                <a class="wrap-img" href="#" target="_blank">
                    <img src="{{ qu.author.image }}" width="50px">
                </a>
                <span class="glyphicon glyphicon-left" aria-hidden="true"></span>

                <br>
                <a href="{{ url_for('person',user_id=qu.author.id) }}">{{ qu.author.username }}</a>
                <span class="badge">評論時間:{{ qu.creat_time }}</span>
                <p style="">{{ qu.detail }}
                </p>


            </li>
     {% endfor %}
    </ul>

2.全部評論排序
uquestion = db.relationship('Question', backref=db.backref('comments', order_by=creat_time.desc))app

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'))

3.顯示評論條數
{{ ques.comments|length }}函數

<div class="container">
    <div class="row clearfix">
        <div class="col-md-2 column">
        </div>
        <div class="col-md-6 column">


<h1><img src="{{ img }}" width="50px">{{usern }}</h1>

    <br>所有問答


<div class="basic_box" style="padding-bottom: 50px;">
    <ul class="list-group">

           {% for qu in ques %}

            <li class="list-group-item" style="width: 800px">

<a class="wrap-img" href="#" target="_blank">
                    <img src="{{ qu.author.image }}" width="50px">
                </a>
                <span class="glyphicon glyphicon-left" aria-hidden="true"></span>
                <a href="{{ url_for('person',user_id=qu.author.id) }}" target="_blank">{{ qu.author.username }}</a>
                <br>
                <a href="{{ url_for('detail',question_id=qu.id) }}">{{qu.title }}</a>

                <br>
                <span class="badge">發佈時間:{{ qu.creat_time }}</span>
                <p style="">{{ qu.detail }}
                </p>



            </li>
     {% endfor %}
    </ul>
</div>

<h1><img src="{{ img }}" width="50px">{{usern }}</h1>
    <br>所有評論



<div class="basic_box" style="padding-bottom: 50px;">
    <ul class="list-group" style="margin-bottom: 10px">
      {% for qu in users %}


            <li class="list-group-item" style="width: 800px">


                <a class="wrap-img" href="#" target="_blank">
                    <img src="{{ qu.author.image }}" width="50px">
                </a>
                <span class="glyphicon glyphicon-left" aria-hidden="true"></span>

                <br>
                <a href="#">{{ qu.author.username }}</a>
                <span class="badge">評論時間:{{ qu.creat_time }}</span>
                <p style="">{{ qu.detail }}
                </p>


            </li>
     {% endfor %}
    </ul>
<br>
<br>
<h1><img src="{{ img }}" width="50px">{{usern }}</h1>
    <br>我的信息

<div class="basic_box" style="padding-bottom: 80px;">
    <ul class="list-group" style="margin-bottom: 10px"><li class="list-group-item" style="width: 800px"> 用戶:{{ usern }}</li>
          <li class="list-group-item" style="width: 800px"> 發佈問答:{{ ques|length }}</li>
          <li class="list-group-item" style="width: 800px"> 評論:{{ comment|length }}</li></ul>
        </div>
        <div class="col-md-4 column">
        </div>
    </div>
</div>
</div>
</div>

4.完成我的中心url

用戶:spa

<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>

 主函數code

@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)

向前端頁面傳遞參數htm

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

各個頁面連接到我的中心blog

#首頁用戶名連接到我的中心
<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>
相關文章
相關標籤/搜索