12.2

首页列表显示全部问答:

  1. 将数据库查询结果传递到前端页面 Question.query.all()
  2. 前端页面循环显示整个列表。
  3. 问答排序
    @app.route('/')
    def index():
        context={
            "questions":Question.query.order_by('create_time').all()
    
        }
        return render_template('base.html',**context)

    完成问答详情页布局:

    1. 包含问答的全部信息
    2. 评论区
    3. 以往评论列表显示区。
      {% block body %}
      
      <h1>提问详情</h1>
      <div class="container">
          <div class="row clearfix">
              <div class="col-md-12 column">
                  <h3 class="text-center">
                      title
                  </h3>
                  <p class="text-center">
                       detail
                  </p>
                  <form role="form">
                      <div class="form-group">
                           <label for="exampleInputAnswer">Write down your answer</label><input type="answer" class="form-control" id="exampleInputAnswer1" />
                      </div>
                       <button type="submit" class="btn btn-default">Submit</button>
                  </form>
              </div>
          </div>
      </div>
      {% endblock %}
    4. 在首页点击问答标题,链接到相应详情页。
      {% block main %}
          <p>{{ username }} contextx</p>
          <ul class="new-list">
              {% for foo in questions %}
                  <li class="list-group"
                      style="padding-left: 0px; padding-right: 10px; box-shadow: rgba(0, 0, 0, 0.498039) 0px 0px 0px 0px;">
                      <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>
                      <a href="#">{{ foo.author.username }}</a><br>
                      <a href="{{ url_for('detail',questions_id=foo.id) }}">{{ foo.title }}</a>{#链接到相关详情页#}
                      <span class="time" >{{ foo.create_time }}</span>
                      <p>{{ foo.detail }}</p>
                  </li>
              {% endfor %}
          </ul>
      {% endblock %}

       

posted @ 2017-12-02 19:57  037吴宜珊  阅读(207)  评论(0)    收藏  举报