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

 

  1. 首页列表显示全部问答:
    1. 将数据库查询结果传递到前端页面 Question.query.all()
    2. 前端页面循环显示整个列表。
    3. 问答排序
    4. index.html
      {% extends 'base.html' %}
      {% block title %}首页{% endblock %}
      {% block head %}
          <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
          <link rel="stylesheet" type="text/css" href="../static/css/index.css">
      {% endblock %}
      {% block main %}
          <div class="question-box">
              <img src=https://wx2.sinaimg.cn/mw690/72ae04f1gy1fm1282v31sj218g1wde82.jpg style="width: 50px">
              <ul class="list-group">
                  <li clsss="list=group-item">
                      <span class="glyphicon glyhicon-leaf" aria-hidden="true"></span>
                      <a href="https://wx2.sinaimg.cn/mw690/637dee21ly1fm12yb1cqrj20w01d8tq1.jpg">Kris wu{{ user }}</a><br>
                      <a href="https://wx2.sinaimg.cn/mw690/72ae04f1gy1fm1282v31sj218g1wde82.jpg">最新街拍{{ title }}</a><br>
                   <span class="badge">上线时间{{ time }}</span>
                      <p style="color: indianred">pictures{{ detail }}
                      </p>
                      <ul class="news-list">
              {% for foo in questions %}
              <li class="list-group-item">
                  <span class="glyphicon glyphicon-leaf" 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>
            <div class="img">
              <a herf="https://wx2.sinaimg.cn/mw690/637dee21ly1fm12yb1cqrj20w01d8tq1.jpg">
                              <img src="https://wx2.sinaimg.cn/mw690/72ae04f1gy1fm1282v31sj218g1wde82.jpg"></a>
             <div class="desc">
               <a href="https://wx2.sinaimg.cn/mw690/72ae04f1gy1fm1282v31sj218g1wde82.jpg>burberry</a>
               </div>
      py
      @app.route('/')
      def index():
          context = {
              'questions': Question.query.order_by('creat_time').all()
          }
          return render_template('index.html',**context)

       

  2. 完成问答详情页布局:
    1. 包含问答的全部信息
    2. 评论区
    3. 以往评论列表显示区。
    4. html
      
          {% for foo in questions %}
              <li class="list-group-item">
                  <span class="glyphicon glyphicon-leaf" 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 %}

       

  3. 在首页点击问答标题,链接到相应详情页。
py
@app.route(
'/detail/<questions_id>') def detail(questions_id): quest = Question.query.filter(Question.id == questions_id).first() return render_template('detail.html',quest = quest)

 

posted on 2017-12-05 18:40  lishanting  阅读(159)  评论(0)    收藏  举报