文章詳情頁
python - django模板 include模板的數據問題
瀏覽:117日期:2022-08-17 17:16:36
問題描述
如:views.py返回是return render(request, ’index.html’)而index.html內容是:
{% include ’header.html’ %}
然后header.html的內容可以是動態的嗎?怎么寫,謝謝!
{{text}}
問題解答
回答1:header可以是動態的,但是動態的變量需要render時渲染出去.如:
header.html
<script src='http://www.cgvv.com.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>
相關文章:
1. 數據庫 - mysql聯表去重查詢2. 用tp5框架寫sql語句3. 【python|scapy】sprintf輸出時raw_string轉string4. docker Toolbox在win10 家庭版中打開報錯5. mysql - 數據庫為什么需要鎖機制?6. python - 我已經連上了美國的VPN,而且在瀏覽器里查看的game排行也是美國的,可是為啥我用代碼怎么爬都是中國地區排行7. 就一臺服務器,mysql數據庫想實現自動備份,如何設計?8. mysql 能不能創建一個 有列級函數 的聯合視圖?9. python3.x - 關于Python圖遍歷的操作10. python小白 問關于參數無法找到的問題
排行榜
