文章詳情頁
python - django模板 include模板的數(shù)據(jù)問題
瀏覽:251日期:2022-08-17 17:16:36
問題描述
如:views.py返回是return render(request, ’index.html’)而index.html內(nèi)容是:
{% include ’header.html’ %}
然后header.html的內(nèi)容可以是動(dòng)態(tài)的嗎?怎么寫,謝謝!
{{text}}
問題解答
回答1:header可以是動(dòng)態(tài)的,但是動(dòng)態(tài)的變量需要render時(shí)渲染出去.如:
header.html
<script src='http://www.leifengta.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>
相關(guān)文章:
1. 測(cè)試自動(dòng)化html元素選擇器元素ID或DataAttribute [關(guān)閉]2. html5和Flash對(duì)抗是什么情況?3. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?4. javascript - QQ第三方登錄的問題5. node.js - mongodb查找子對(duì)象的名稱為某個(gè)值的對(duì)象的方法6. 利用IPMI遠(yuǎn)程安裝centos報(bào)錯(cuò)!7. 在mac下出現(xiàn)了兩個(gè)docker環(huán)境8. spring-mvc - spring-session-redis HttpSessionListener失效9. java - Spring boot 讀取 放在 jar 包外的,log4j 配置文件,系統(tǒng)有創(chuàng)建日志文件,不寫入日志信息。10. 正在使用electron和node.js做桌面應(yīng)用,需要實(shí)時(shí)監(jiān)聽是否有網(wǎng)絡(luò)連接,node或者electron是否可以做到
排行榜

熱門標(biāo)簽
網(wǎng)公網(wǎng)安備