文章詳情頁
python - django模板 include模板的數(shù)據(jù)問題
瀏覽:257日期:2022-08-17 17:16:36
問題描述
如:views.py返回是return render(request, ’index.html’)而index.html內(nèi)容是:
{% include ’header.html’ %}
然后header.html的內(nèi)容可以是動態(tài)的嗎?怎么寫,謝謝!
{{text}}
問題解答
回答1:header可以是動態(tài)的,但是動態(tài)的變量需要render時渲染出去.如:
header.html
<script src='http://m.b3g6.com/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. javascript - sublime快鍵鍵問題2. javascript - immutable配合react提升性能?3. css - 寫頁面遇到個布局問題,求大佬們幫解答,在線等,急!~4. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點疑問5. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問?6. 實現(xiàn)bing搜索工具urlAPI提交7. 配置Apache時,添加對PHP的支持時語法錯誤8. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化9. javascript - 移動端上不能實現(xiàn)拖拽布局嗎?10. phpstudy8.1支持win11系統(tǒng)嗎?
排行榜

熱門標(biāo)簽
網(wǎng)公網(wǎng)安備