12.6
主PY文件寫視圖函數,帶id參數。?
@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)
首頁標題的標簽做帶參數的鏈接。
? ? ? {{ url_for('detail',question_id = foo.id) }{% for foo in questions %}
在詳情頁將數據的顯示在恰當的位置。?
{{ 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 %}
建立評論的對象關系映射:
class Comment(db.Model):
? ? __tablename__='comment'
?
?
?
轉載于:https://www.cnblogs.com/chenyanxi123/p/7992872.html
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結