文章詳情頁
python - django模板 include模板的數據問題
瀏覽:181日期: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://m.propowerdrill.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. java - 關于表的主鍵問題2. 通過外部CSS或嵌入式樣式縮放時,Firefox會使圖像模糊。3. html5 - 如何讓H5頁面在手機瀏覽器里和微信全屏顯示4. 誰有mysql5.7安裝的詳細教程5. node.js - session怎么存到cookie,然后服務器重啟后還能獲取。數據庫不用mongodb或redis,數據庫是mysql6. Android的webView如何實現網頁 錄音功能?7. java中使用log4j如何不用每次調用都聲明一下?8. nginx - web服務器根目錄生成了很多這種文件?9. 這段代碼是獲取百度收錄量的!需要怎么設置才能獲取百度快照旁邊的網址呢?10. html5 - vue 里的Elemen UI的時間怎么轉化為時間戳嗎
排行榜
