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

  1. 首页列表显示全部问答:
    1. 将数据库查询结果传递到前端页面 Question.query.all()
      @app.route('/')
      def home():
          context={
              'question':Question.query.order_by('creat_time').all()
          }
          return render_template('shouye.html',**context)

       

    2. 前端页面循环显示整个列表。
    3. 问答排序
      <ul class="comment">
          <img class="comment_pic"  src="../static/images/comment.png">
          <p class="wenzi">Question</p>
          {% for foo in question %}
              <li class="detail">
                  <span class="icon" aria-hidden="true"></span>
                  <a href="#">{{foo.author.username}}</a>
                  <br>
                  <a href="#">{{foo.title}}</a>
                  <span class="badge">{{foo.creat_time}}</span>
                  <p style="text-indent: 18px">{{foo.detail}}</p>
              </li>
          {% endfor %}
      </ul>

       

  2. 完成问答详情页布局:
    1. 包含问答的全部信息
    2. 评论区
    3. 以往评论列表显示区。
      {% extends 'base.html' %}
      {% block title %}
          detail
      {% endblock  %}
      
      {% block head %}
          <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/detail.css') }}">
      {% endblock  %}
      
      {% block main %}
      
      <body>
      <form class="demo-form">
          <h3>Title Test</h3>
          <span>author</span>
          <hr>
          <text>detail</text><br><br>
           <textarea class="form-control" id="question" placeholder="请输入"></textarea><br><br>
      <input type="submit" value="提交" style="float: right">
      </form>
      </body>
      
      {% endblock %}

       

  3. 在首页点击问答标题,链接到相应详情页。

posted on 2017-12-05 16:18  106洪瑜  阅读(146)  评论(0编辑  收藏  举报