首页列表显示全部问答,完成问答详情页布局
- 首页列表显示全部问答:
- 将数据库查询结果传递到前端页面 Question.query.all()
- 前端页面循环显示整个列表。
- 问答排序
- 完成问答详情页布局:
- 包含问答的全部信息
- 评论区
- 以往评论列表显示区。
- 在首页点击问答标题,链接到相应详情页。
@app.route('/detail/<post_id>')
def detail(post_id):
post=Post.query.filter(Post.id==post_id).first()
return render_template('detail.html', post=post)
@app.route('/')
def jianshu():
context={
'post':Post.query.order_by('-creat_time').all()
}
return render_template('jianshu.html',**context)
{% extends 'jianshu.html' %} {% block title %}问答详情{% endblock %} {% block main %} <div class="page-header"> <h3>题目:{{ post.title }} <br><small>作者:{{ post.author_id }}发布时间:{{ post.creat_time }} </small></h3> </div> <p class="lead">详情:{{ post.detail }} </p> <br> <form action="{{ url_for('post') }}" method="post"></form> <div class="form-group"> <textarea name="new_comment" id="new_comment" rows="3" placeholder="请写下你的评论"></textarea> </div> <button type="submit" class="btn btn-default" onclick="">发送</button> </form> <ul class="list-group" style="margin: 10px"></ul> {% endblock %}