是否可以在django中与包含的模板共享上下文?例如,假设我们有:
base.html
<html>
<head>...<head>
<body>
{% block content %}{% endblock %}
</body>
mypage.html
{% extends 'base.html' %}
{% block content %}
Hi this is my template !
{% include 'my_fragment.html' %}
{% endblock %}
my_fragment.html
<div> I want to use the context here ! </div>
我的观点是调用模板mypage.html
。我不能称其为my_fragment.html
扩展,mypage.html
因为它只是我页面的一小部分。如何在不使用以下命令发送视图的所有参数的情况下做到这一点:
{% include 'my_fragment.html' with somevar=myvar %}
谢谢 !
我相信它是默认包含的。文件
包含的模板在包含它的模板的上下文中呈现。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句