文章詳情頁
python - django模板 include模板的數據問題
瀏覽:110日期: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.aoyou183.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. java - 請問在main方法中寫成對象名.屬性()并賦值,與直接參參數賦值輸錯誤是什么原因?3. MySQL數據庫中文亂碼的原因4. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””5. docker不顯示端口映射呢?6. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?7. android studio總是在processes running好久8. angular.js - 關于$apply()9. docker-compose 為何找不到配置文件?10. dockerfile - 我用docker build的時候出現下邊問題 麻煩幫我看一下
排行榜
