首页列表显示全部问答,完成问答详情页布局。

  1. 首页列表显示全部问答:
    1. 将数据库查询结果传递到前端页面 Question.query.all()
    2. 前端页面循环显示整个列表。
    3. 问答排序
  2. 完成问答详情页布局:
    1. 包含问答的全部信息
    2. 评论区
    3. 以往评论列表显示区。
  3. 在首页点击问答标题,链接到相应详情页。
    @app.route('/')
    def index():
        context = {
              'questions': Question.query.all()
        }
        return render_template('index.html',**context)
    {% 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 %}
        <p>{{ username }}欢迎您来到首页!</p>
    <div id="list-container">
        <ul class="note-list" style="margin:80px auto;width: 1000px;height:800px;background: #FFF;border-radius: 20px;opacity:0.6;filter:alpha(opacity=60);">
            {% for foo in questions %}
                <li class="note-list-item">
                    <div class="contain">
                        <span class="glyphion glyphion-leaf" aria-hidden="true"></span>
                        <a href="#">{{ foo.author.username }}</a>
                        <br>
                        <br>
                        <a href="#">{{ foo.title }}</a><span class="badge">{{ foo.creat_time }}</span>
                        <p style="width: 450px;"> 详情 {{ foo.detail }}</p>
                    </div>
                </li>
            {% endfor %}
        </ul>
    </div>
    {% endblock %}
    

      

     

posted on 2017-12-05 21:48  072苏喜虹  阅读(138)  评论(0)    收藏  举报

导航