我有一个模板plot.html
应用程序plot
:
<div>
{{ plot|safe }}
</div>
some other divs here
绘图变量是根据应用程序内的views.py
计算的:
class RenderView(TemplateView):
def __init__(self):
self.template_name = "plot.html"
def get_context_data(self, **kwargs):
context = super(RenderView, self).get_context_data(**kwargs)
context['plot'] = PlotView().make_plot()
return context
现在,我想将此模板与生成的图一起包含在另一个应用程序中的另一个模板中。html:
{% include "plot.html" %}
当然,这不会从views.py文件中生成图和其他信息。
我一直在阅读有关模板标签(https://docs.djangoproject.com/en/en/2.0/howto/custom-template-tags/(,但是我不确定在poll_extras.py中有什么标签是正确的解决方案。
您需要使用它传递变量。
{% include "plot.html" with plot=plot only %}
,但是您需要从调用view
传递它,否则您可能想选择一个标签。
(only
可防止您将整个context
复制到其他模板(