文章詳情頁
python - django模板 include模板的數據問題
瀏覽:114日期: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.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. android - NavigationView 的側滑菜單中如何保存新增項(通過程序添加)2. tp5 不同控制器中的變量調用問題3. 微信小程序可以用gulp,webpack嗎?4. mysql服務無法啟動1067錯誤,誰知道正確的解決方法?5. ueditor上傳服務器提示后端配置項沒有正常加載,求助?。。。?!6. python - 為什么正常輸出中文沒有亂碼,zip函數之后出現中文編程unicode編碼的問題,我是遍歷輸出的啊。7. 老師 我是一個沒有學過php語言的準畢業生 我希望您能幫我一下8. 這段代碼既不提示錯誤也看不到結果,請老師明示錯在哪里,謝謝!9. php7.3.4中怎么開啟pdo驅動10. 提示語法錯誤語法錯誤: unexpected ’abstract’ (T_ABSTRACT)
排行榜
