- 主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 }}- py:
-
@app.route('/detail/<question_id>') def detail(question_id): quest = Question.query.filter(Question.id == question_id).first() return render_template('detail.html',ques=quest)
2.
<li class="post_item_summary "> <a class="titlelnk" target="_self" href="{{ url_for('detail',question_id=foo.id) }}">{{ foo.title }}</a><br> <a href="#" class="lightblue">{{ foo.author.username }}</a> <br> <img width="48" height="48" class="pfs" src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4066191998,32277144&fm=27&gp=0.jpg" alt=""> <p class="post_item_summary "> {{ foo.detail }} </p> <span class="post_item_foot"> 发布于 {{ foo.create_time }} </span> </li>
3.
<div> <h3 class="title ">{{ques.title}}<br><small>{{ ques.author.username }}<span>{{ ques.create_time }} </span> </small></h3> </div> <p style="color: #333;">{{ ques.detail }}</p>
01-31