1. 首页列表显示全部问答:
    1. 将数据库查询结果传递到前端页面 Question.query.all()
    2. 前端页面循环显示整个列表。
    3. 问答排序
  2. 完成问答详情页布局:
    1. 包含问答的全部信息
    2. 评论区
    3. 以往评论列表显示区。
  3. 在首页点击问答标题,链接到相应详情页。
 1 @app.route('/')
 2 def index():
 3     context = {
 4         'questions':Question.query.order_by('-creat_time').all()
 5     }
 6     return render_template('index首页.html',**context)
 7 
 8 
 9 
10 @app.route('/detail/<question_id>')
11 def detail(question_id):
12 
13     return render_template('detail.html',ques = question_id)
14 
15 
16 
17 {% extends 'base父模板.html' %}
18 {% block title %}问答详情{% endblock %}
19 <meta charset="UTF-8">
20 
21 {% block main %}
22 
23     <div class="page-header">
24         <h3>Title {{ ques }}<br>
25             <small>author r</small>
26         </h3>
27     </div>
28     <p class="lead">detail</p>
29     <hr>
30 
31     <form action="{{ url_for('question') }}" method="post" style="align-content: center">
32         <div class="form-group">
33             <textarea name="new_comment" id="new_comment" cols="30" rows="3" class="form-control"
34                       placeholder="请输入问答内容"></textarea>
35         </div>
36         <button type="submit" class="btn btn-default">发送</button>
37     </form>
38     <ul class="list-group" style="margin: 10px"></ul>
39 {% endblock %}

 

posted on 2017-12-01 09:57  016李云基  阅读(95)  评论(0编辑  收藏  举报