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

  1. 首页列表显示全部问答:
    1. 将数据库查询结果传递到前端页面 Question.query.all()
    2. 前端页面循环显示整个列表。
    3. 问答排序
  2. 完成问答详情页布局:
    1. 包含问答的全部信息
    2. 评论区
    3. 以往评论列表显示区。
  3. 在首页点击问答标题,链接到相应详情页。

 

@app.route('/')
def first():
    context = {
        'questions': Question.query.all()
    }
    return render_template('first.html',**context)

@app.route('/question_detail/')
def question_detail():
    return render_template('question_detail.html')

 

{% extends 'base.html' %}
{% block title %}首页*{% endblock %}
 {% block head %}
 <link href="{{url_for('static',filename='css/first.css') }}" rel="stylesheet" type="text/css">
{% endblock %}

{% block main %}
<p class="slogan">欢迎你,{{username}}</p>
    {% for foo in questions %}
        <ul class="list-group">
        <li class="list-group-item">
            <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>
            <a href="{{ url_for('question_detail' ,question_id=foo.id)}}">id:{{ foo.author.username }}</a>
            <br>
            <a >标题:{{ foo.question }}</a>
            <br>
            <a >详情:{{ foo.questionDetail }}</a>
            <br>
          <span class="badge">{{ foo.creat_time }}</span>
        </li>
        </ul>
     {% endfor %}


{% endblock %}

 

{% extends'base.html' %}
{% block title %}
    详情*
{% endblock %}
{% block head %}
    <link rel="stylesheet" href="{{ url_for('static',filename='css/question_detail.css')}}" type="text/css">
{% endblock %}
{% block main %}
<body>
<div class="detail">
    <div class="detail_left">
    <h3>标题</h3>
    <a>用户名</a>
<span class="badge">创建时间</span>
    <hr>
    <a>详情</a>
    <hr>
    <textarea name='comment' class="form-control" rows="8" id="questionDetail"></textarea>
    <br><button class="btn-default">发布</button>
    <p>评论:</p>
    <li class="comment">
        <span class="icon" aria-hidden="true"></span>
        <a href="#" style="float: left;margin:3px auto; line-height:12px;">用户名</a>
         <span class="badge2">发布时间</span>
        <br><hr>
        <p class="neirong">详情</p>
    </li>
     <li class="comment">
        <span class="icon" aria-hidden="true"></span>
        <a href="#" style="float: left;margin:3px auto; line-height:12px;">用户名</a>
         <span class="badge2">发布时间</span>
        <br><hr>
        <p class="neirong">详情</p>
    </li>

</div>
</div>
</body>
{% endblock %}

 

 

posted @ 2017-12-06 14:02  011赖颖璇  阅读(133)  评论(0编辑  收藏  举报