首頁列表顯示所有問答,完成問答詳情頁佈局。

  1. 首頁列表顯示所有問答:
    1. 將數據庫查詢結果傳遞到前端頁面 Question.query.all()
    2. 前端頁面循環顯示整個列表。
    3. 問答排序
  2. 完成問答詳情頁佈局:
    1. 包含問答的所有信息
    2. 評論區
    3. 以往評論列表顯示區。
  3. 在首頁點擊問答標題,連接到相應詳情頁。

 

py:css

@app.route('/')
def index():
    context = {
        'question':Question.query.all()
    }
    return render_template('index.html',**context)


@app.route('/detail/<question_id>')
def detail(question_id):
        quest = Question.query.filter(Question.id == question_id).first()
        return render_template('detail.html', ques=quest)

html:html

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

{% block head %}
    <link rel="stylesheet" href="{{ url_for('static',filename='css/index.css')}}" type="text/css">
{% endblock %}

{%  block main %}
    <img src="{{ url_for('static',filename='images/qalogo.jpg') }}"alt="qa">
    <p>{{ username }}context</p>
    <ul class="list-group" style="margin-top: 6.2% ; margin-left: 25%;width: 50%; ">
        {% for foo in question %}
            <li class="list-group-item">
                <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>
                <a href="{{ url_for('detail',queation_id = foo.id) }}">{{ foo.title}}</a>
                <a style="text-indent: 18px">{{ foo.detail }}</a>
                <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>
                <a href="{{ url_for('usercenter',user_id=foo.author_id) }}">{{ foo.author.username }}評論:({{ foo.comments|length }})</a>
                <span class="badge">{{ foo.create_time }}</span>

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


</body>
{% endblock %}
</html>

 

相關文章
相關標籤/搜索