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

    1.顯示全部評論 {% for foo in ques.comments %}javascript

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

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

    4.完成我的中心前端

1.我的中心的頁面佈局(html文件及相應的樣式文件)java

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

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

4.頁面顯示相應數據佈局

發佈的所有問答post

發佈的所有評論url

我的信息

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

index.html

{% extends'base.html' %}
    {% block title %}
    首頁
    {% endblock %}
{% block head %}

    <script src="{{url_for('static',filename='js/base.js') }}" type="text/javascript"></script>
    <link href="{{ url_for('static' ,filename='css/base.css') }}"  rel="stylesheet" type="text/css">
    {% endblock %}
    {% block main %}

    {% for foo in question %}
<body id="myBody">
        <div id="gufeng">
        <a href="{{ url_for('usercenter',user_id = foo.author_id) }}">{{ foo.author.username }}評論({{ foo.comments|length }})</a>
       <ul class="list" >
             <li>用戶名:{{ foo.author.username }}</li>
          <a href="{{ url_for("detail",question_id=foo.id) }}">標題:{{ foo.title }}</a>
           <li class="">問題:{{ foo.detail }}</li>
           <li class="">時間:{{ foo.time }}</li>
       </ul>
        </div>
    {% endfor %}
    <footer>
        <div class="footer_box">
            Copyright@2017-2027 我的版權,版權全部 做者:JZX telephone:0000-1234567 mobile phone:11111111111
        </div>
    </footer>
{% endblock %}

 detail.html

% extends "base.html" %}
{% block title%}詳細內容{% endblock %}

{% block main %}
<body bgcolor="#ffd700">
    <div class="GuFeng">
        <a href="{{ url_for('usercenter',user_id = foo.author.id) }}">{{ foo.author.username }}</a>
        {   <form action="{{ url_for('/detail/<question_id>') }}" method="post">}
      <h2>標題:{{ ques.title }}</h2><br>
      <h3>用戶名:{{ ques.author.username }}</h3><br>
      <h3> 發佈時間:{{ ques.create_time }}</h3>
      <p>內容:{{ ques.detail }}</p>
        <hr>
        <textarea class='comment'rows="10"id="detail"name="detail"></textarea>
        <br><input  type="submit" value="發佈"style="width:100px;height:50px;font-size:50px">
        <input name="question_id" type="hidden" value="{{ ques.id }}"/>
        <p>評論:</p>
        <table border=5 style="background: gold"width="50">
            <tr><td>評論內容</td></tr>
            <tr><td>評論內容</td> </tr>
            <tr><td>評論內容</td></tr>
            </tr>
        </table>
    </div>
</body>
{% endblock %}

 usercenter.html

{% extends'base.html' %}
{% block title %}
    我的中心
{% endblock %}
{% block head %}
    <link rel="stylesheet" href="{{ url_for('static',filename='css/user.css')}}" type="text/css">
{% endblock %}
{% block main %}
<div class="all question">
     <h2><a href="{{ url_for('usercenter',user_id=user.id) }}"> {{ user.username }}</a>所有問答</h2>
      <ul class="wenda" style="width: auto">
          {% for foo in user.question %}
             <li class="wenti">
                 <a href="#">{{ foo.author.username }} </a>
                <span>{{ foo.creat_time }}</span><br>
                <a class="title" href="{{ url_for('detail',question_id=foo.id) }}">{{ foo.title }}</a><br>
                <p>{{ foo.detail }}</p>
             </li>
           {% endfor %}
      </ul>
</div>

<div class="all detail" >
    <h2><a href="{{ url_for('usercenter',user_id=user.id) }}"> {{ user.username }}</a>所有評論</h2>
    <ul class="pinglun" style="width: auto">
        {% for foo in user.comments %}
        <li class="comment">
             <a href="#">{{ foo.author.username }} </a>
                <span>{{ foo.creat_time }}</span><br>
                <p>{{ foo.detail }}</p>
        </li>
        {% endfor %}
    </ul>
</div>

<div class="usercenter">
     <h2><a href="{{ url_for('usercenter',user_id=user.id) }}"> {{ user.username }}</a>我的中心</h2>
     <ul class="yonghu" style="width: auto">
            <li><p>用戶:{{ user.username }}</p></li>
            <li><p>編號:{{ user.id }}</p></li>
            <li><p>暱稱:{{ user.nickname}}</p></li>
            <li><p>文章篇數:{{ user.question|length }}</p></li>
     </ul>
</div>
{% endblock %}

 py

@app.route('/usercenter/<user_id>')
@loginFirst
def usercenter(user_id):
    user=User.query.filter(User.id==user_id).first()
    context={
        'user':user
    }
    return render_template('center.html',**context)
相關文章
相關標籤/搜索