文章詳情頁
python - django模板 include模板的數(shù)據(jù)問題
瀏覽:175日期: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.piao2010.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. docker內(nèi)創(chuàng)建jenkins訪問另一個容器下的服務(wù)器問題2. 如何解決Centos下Docker服務(wù)啟動無響應(yīng),且輸入docker命令無響應(yīng)?3. 我在centos容器里安裝docker,也就是在容器里安裝容器,報錯了?4. html - css 使用字體的時候,格式有什么特殊要求嗎?5. html5 - 百度echart官網(wǎng)下載的地圖json數(shù)據(jù)亂碼6. css3 - 學(xué)習(xí)css構(gòu)建圖形時,遇到一個很有意思的現(xiàn)象,具體代碼如下7. javascript - js閉包作用域8. javascript - echart+百度地圖9. 極光推送 - Android app消息推送 百度 極光 個推 信鴿哪個好一些?10. 微信開放平臺 - android 微信支付后點完成按鈕,后回調(diào)打開第三方頁面,屏幕閃動,求解決方法
排行榜

熱門標(biāo)簽