文章詳情頁
python - django模板 include模板的數據問題
瀏覽:134日期: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. macos - mac下docker如何設置代理2. dockerfile - 為什么docker容器啟動不了?3. 請教各位大佬,瀏覽器點 提交實例為什么沒有反應4. dockerfile - 我用docker build的時候出現下邊問題 麻煩幫我看一下5. javascript - webapp業務流程基本一致,多套主題(樣式基本不一樣,交互稍有偏差)管理,并且有不斷有新增主題,該如何設計組件化架構?6. mysql - AttributeError: ’module’ object has no attribute ’MatchType’7. apache - 本地搭建wordpress權限問題8. javascript - web網頁版app返回上一頁按鈕在ios設備失效怎么辦?安卓上可以,代碼如下,請大神幫助,萬分感謝。9. 新手 - Python 爬蟲 問題 求助10. javascript - JS設置Video視頻對象的currentTime時出現了問題,IE,Edge,火狐,都可以設置,反而chrom卻...
排行榜
