- 主PY文件写视图函数,带id参数。
-
@app.route('/detail/<question_id>')
def detail(question_id):
quest =
return render_template('detail.html', ques = quest)
- 首页标题的标签做带参数的链接。
- {{ url_for('detail',question_id = foo.id) }}
- 在详情页将数据的显示在恰当的位置。
{{ ques.title}}
{{ ques.id }}{{ ques.creat_time }}
{{ ques.author.username }}
{{ ques.detail }}
@app.route('/detail/<post_id>')
def detail(post_id):
post=Post.query.filter(Post.id==post_id).first()
return render_template('detail.html', pos=post) # 页面上用pos,函数用post,传递到pos
{% block main %}
<!--<img src="{{ url_for }}">-->
<ul class="list-group">
{% for foo in post %}
<li class="list-group-item" >
<span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>
<a href="#">{{ foo.author.username }}</a>
<br>
<a href="{{url_for('detail',post_id=foo.id)}}">{{foo.title}}</a>
<span class="badge">{{ foo.creat_time }}</span>
<p style="">{{ foo.detail }}</p>
</li>
{% endfor %}
</ul>
{% extends 'jianshu.html' %}
{% block title %}问答详情{% endblock %}
{% block main %}
<div class="page-header">
<h3>题目:{{ pos.title }}
<br><small>作者:{{ pos.author_id }}发布时间:{{ pos.creat_time }}
</small></h3>
</div>
<p class="lead">详情:{{ pos.detail }} </p>
<br>
<form action="{{ url_for('post') }}" method="post"></form>
<div class="form-group">
<textarea name="new_comment" id="new_comment" rows="5" placeholder="请写下你的评论"></textarea>
</div>
<button type="submit" class="btn btn-default" onclick="">发送</button>
</form>
<ul class="list-group" style="margin: 10px"></ul>
{% endblock %}