12.6
主PY文件寫視圖函數(shù),帶id參數(shù)。?
@app.route('/detail/<question_id>')def detail(question_id):
? ? quest =?
? ? return render_template('detail.html', ques = quest) @app.route('/xiangqing/<question_id>') def xiangqing(question_id):quest=question.query.filter(question.id==question_id).first()return render_template('xiangqing.html',quse=quest)
首頁標(biāo)題的標(biāo)簽做帶參數(shù)的鏈接。
? ? ? {{ url_for('detail',question_id = foo.id) }{% for foo in questions %}
在詳情頁將數(shù)據(jù)的顯示在恰當(dāng)?shù)奈恢谩?
{{ ques.title}}{{ ques.id? }}{{? ques.creat_time }}
?
{{ ques.author.username }}?{{ ques.detail }}
?
<li class="list-group-item" style="clear: both"><span class="glyphicon glyphicon-leaf" aria-hidden="true"></span><a href="#">name:{{ foo.author.username }}</a><br><a href="{{ url_for('xiangqing',question_id=foo.id )}}">title:{{ foo.title }}</a><br><span class="badge">time:{{ foo.creat_time }}</span>
<p style="color: indianred">view:{{ foo.datail }}</p> </li> {% endfor %}
建立評(píng)論的對(duì)象關(guān)系映射:
class Comment(db.Model):
? ? __tablename__='comment'
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/chenyanxi123/p/7992872.html
超強(qiáng)干貨來襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生總結(jié)
- 上一篇: alpha冲刺12
- 下一篇: [ZZOJ#31]类欧几里得