首页 > 其他 > 详细

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

时间:2017-12-05 18:14:25      阅读:830      评论:0      收藏:0      [点我收藏+]

首页列表显示全部问答:

  1. 将数据库查询结果传递到前端页面 Question.query.all()
  2. 前端页面循环显示整个列表。
  3. 问答排序
    @app.route(/)
    def index():
        context = {
            questions: Question.query.order_by(creat_time).all()
        }
        return render_template("index.html", **context)
     <ul class="list-group"style="width: 400px" align="center">
         {% for foo in questions %}
            <li class="list-group-item"style="background-color:lightblue;height:190px;width:400px;">
                <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>
                <a href="{{ url_for(‘detail‘ ,question_id=foo.id)}}">id:{{ foo.author.username }}</a>
                <br>
                <a href="http://www.jianshu.com/">标题:{{ foo.title }}</a>
                <br>
                <p style="color:black">详情:{{ foo.detail }}</p>
                <br>
              <span class="badge"style="margin-left: 50%">{{ foo.creat_time }}</span>
            </li>
    
         {% endfor %}
    
    </ul>
    1. 完成问答详情页布局:
      1. 包含问答的全部信息
      2. 评论区
      3. 以往评论列表显示区。
    2. 在首页点击问答标题,链接到相应详情页。详情html
      {% extends ‘index.html‘ %}
      {% block title %}问答详情{% endblock %}
      {% block main %}
           <div class="container">
              <div class="box">
                  <h3 style="font-family:宋体;text-align: left;font-size: 40px">详情页</h3>
          </div>
                <h2>问题</h2>
                <h2>作者</h2>
          <p class="lead">detail:简书是一个优质的创作社区</p>
          <hr>
          <form action="{{ url_for(‘question‘) }}" method="post">
          <div><textarea class="form-control" id="new_comment" rows="6" placeholder="write your comment"style="height:200px;width:800px" ></textarea><br></div>
          <button type="submit" class="fabu"style="width:100px">发布</button>
          </form>
          <ul class="list-group" style="margin: 10px"></ul>
      </div>
      {% endblock %}

      技术分享图片技术分享图片

       

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

原文:http://www.cnblogs.com/222ya/p/7988555.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!