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

  1. 首页列表显示全部问答:
    1. 将数据库查询结果传递到前端页面 Question.query.all()
    2. 前端页面循环显示整个列表。
    3. 问答排序
      @app.route('/shouye/')
      def shouye():
          context = {
              'questions':Question.query.order_by('create_time').all()
          }
          return render_template('hh.html',**context)
      {% extends 'base.html' %}
      {% block title %}
      首页
      {% endblock %}
      {% block main %}
           <link rel="stylesheet" type="text/css" href="../static/css/hh.css">
          <p>{{ username }}***</p>
      <div class="box">
              <ul class="list-group">
                  {% for foo in questions %}
                      <li class="list-group-item">
                          <img style=" 30px" src="{{ url_for('static',filename='css/touxiang.jpg') }}" alt="64">
                          <a href="#"style="color: red">{{ username }}</a><br>
                          <a href="#"style="color: red">问题:{{ foo.title }}</a><br>
                          <p style="align-content: center">{{ foo.detail }}</p>
                          <span class="badge" style="margin-left: 60%">{{ foo.create_time }}</span>
                          <p style="margin-left: 25%"></p><br>
                      </li>
                  {% endfor %}
              </ul>
      
          </div>
      {% endblock %}
  2. 完成问答详情页布局:
    1. 包含问答的全部信息
    2. 评论区
    3. 以往评论列表显示区。
      {% extends 'base.html' %}
      {% block title %}
          问答详情
      {% endblock %}
      {% block main %}
          <div class="box">
              <h3>Title{{ ques }}
              <br><small>author r</small></h3><hr>
              <p>detail</p>
              <hr>
              <form action="{{ url_for('detail') }}" method="post">
                  <div><textarea class="form-control" id="new_comment" rows="3" style="margin-left: 1%" name="new_comment" placeholder="write your comment"></textarea><br></div>
                  <button type="submit" onclick="foLogin()">发送</button>
              </form>
              <ul class="list-group" style="margin: 10px"></ul>
          </div>
      {% endblock %}
  3. 在首页点击问答标题,链接到相应详情页。
    @app.route('/detail/')
    def detail():
        return render_template('detail.html')
原文地址:https://www.cnblogs.com/00js/p/7992843.html