-
- 主PY文件写视图函数,带id参数。
-
@app.route('/detail/<question_id>')
def detail(question_id):
quest =
return render_template('detail.html', ques = quest)#详情页 @app.route('/detail/<questions_id>') def detail(questions_id): questions=Question.query.filter(Question.id==questions_id).first() return render_template('detail.html',questions=questions)
- 首页标题的标签做带参数的链接。
- {{ url_for('detail',question_id = foo.id) }}
{% block main %} <p>{{ username }} contextx</p> <ul class="new-list"> {% for foo in questions %} <li class="list-group" style="padding-left: 0px; padding-right: 10px; box-shadow: rgba(0, 0, 0, 0.498039) 0px 0px 0px 0px;"> <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span> <a href="#">{{ foo.author.username }}</a><br> <a href="{{ url_for('detail',questions_id=foo.id) }}">{{ foo.title }}</a>{#链接到相关详情页#} <span class="badge" >{{ foo.create_time }}</span> <p>{{ foo.detail }}</p> </li> {% endfor %} </ul> {% endblock %}
-
- 在详情页将数据的显示在恰当的位置。
-
{{ ques.title}}
{{ ques.id }}{{ ques.creat_time }}{{ ques.author.username }}
{{ ques.detail }}
{% extends'base.html' %} {% block title %}问答详情{% endblock %} {% block head %} <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/detail.css') }}"> {% endblock %} {% block main %} <div class="page-header"> <h3>题目:{{ questions.title }}<br><small>作者:{{ questions.author.username }} <span class="badge">发布时间:{{ questions.create_time }}</span></small></h3> </div> <p class="lead">详情:{{ questions.detail }}</p><br> {#发布评论#} <form action="{{ url_for('questions') }}" method="post"> <div class="form-group"> <textarea name="new_comment" class="form-control" rows="3" id="new-comment" placeholder="请写下你的评论"></textarea> <input type="hidden" name="questions_id" value="{{ questions.id }}"> </div> <button type="submit" class="btn btn-default" onclick="fnDetail">发送</button> {# 评论列表#} </form> <h4>评论({{ questions.comments|length }})</h4> <ul class="list-group" style="margin: 10px"></ul> {% endblock %}