文章詳情頁
python - django模板 include模板的數據問題
瀏覽:101日期: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>
相關文章:
排行榜
