文章詳情頁
python - django模板 include模板的數據問題
瀏覽:160日期: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.baoyu77737.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>
相關文章:
1. javascript - 圖片請求失敗怎么去掉左上角的小圖標?2. html5 - 如何解決bootstrap打開模態modal窗口引起頁面抖動?3. python小白 問關于類里面屬性的問題4. javascript - 有什么工具可以自動給css3的樣式 加 前綴 要最簡單的 不會sass less5. javascript - history.replaceState()無法改變query參數6. update方法不能更新字段值為0的數據7. Python爬蟲如何爬取span和span中間的內容并分別存入字典里?8. 老哥們求助啊9. ios - 類似微博首頁,一張圖的時候是如何確定圖大小的?10. html5 - vue 里的Elemen UI的時間怎么轉化為時間戳嗎
排行榜
