文章詳情頁
python - django模板 include模板的數(shù)據(jù)問題
瀏覽:104日期:2022-08-17 17:16:36
問題描述
如:views.py返回是return render(request, ’index.html’)而index.html內(nèi)容是:
{% include ’header.html’ %}
然后header.html的內(nèi)容可以是動(dòng)態(tài)的嗎?怎么寫,謝謝!
{{text}}
問題解答
回答1:header可以是動(dòng)態(tài)的,但是動(dòng)態(tài)的變量需要render時(shí)渲染出去.如:
header.html
<script src='http://www.aoyou183.cn/wenda/{{ static_url(’js/common.js’) }}' type='text/javascript' charset='utf-8'></script><p class='header'> {{ user.username }} </p>
index.html
<html><head></head><body> {% include 'header.html' %} <!--包含了header.html的代碼--> ...</body></html>
相關(guān)文章:
1. python - 獲取到的數(shù)據(jù)生成新的mysql表2. javascript - js 對(duì)中文進(jìn)行MD5加密和python結(jié)果不一樣。3. mysql里的大表用mycat做水平拆分,是不是要先手動(dòng)分好,再配置mycat4. window下mysql中文亂碼怎么解決??5. sass - gem install compass 使用淘寶 Ruby 安裝失敗,出現(xiàn) 4046. python - (初學(xué)者)代碼運(yùn)行不起來,求指導(dǎo),謝謝!7. 為啥不用HBuilder?8. python - flask sqlalchemy signals 無法觸發(fā)9. python的文件讀寫問題?10. 為什么python中實(shí)例檢查推薦使用isinstance而不是type?
排行榜

熱門標(biāo)簽