python - django模板 include模板的数据问题
本文介绍了python - django模板 include模板的数据问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
如:views.py返回是return render(request, 'index.html')
而index.html内容是:
{% include 'header.html' %}
然后header.html的内容可以是动态的吗?怎么写,谢谢!
{{text}}
解决方案
header可以是动态的,但是动态的变量需要render时渲染出去.
如:
header.html
<script src="{{ static_url('js/common.js') }}" type="text/javascript" charset="utf-8"></script>
<div class="header">
{{ user.username }}
</div>
index.html
<html>
<head>
</head>
<body>
{% include "header.html" %} <!--包含了header.html的代码-->
...
</body>
</html>
这篇关于python - django模板 include模板的数据问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文