【发布时间】:2014-04-16 15:13:19
【问题描述】:
是否可以与 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。我不能调用 make my_fragment.html extends mypage.html 因为它只是我页面的一小部分。如何在不发送视图的所有参数的情况下做到这一点:
{% include 'my_fragment.html' with somevar=myvar %}
谢谢!
【问题讨论】:
标签: django templates inheritance include