我在应用------------ ---------- -------------- -------------------
| Download | ---> | Decode | ---> | CSV in GCS | ---> | CSV to BigQuery |
------------ ---------- -------------- -------------------
中有一个模板plot.html
:
plot
绘图变量是根据app plot中的<div>
{{ plot|safe }}
</div>
some other divs here
计算的:
views.py
现在我想将此模板与生成的情节和其他div一起包含在另一个应用程序另一个模板的另一个模板中:
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
当然这不会生成来自views.py文件的图和其他信息。
我一直在阅读有关模板标签(https://docs.djangoproject.com/en/2.0/howto/custom-template-tags/)的内容,但我不确定poll_extras.py中的内容是什么,或者标签是否是正确的解决方案。
答案 0 :(得分:2)
您需要使用它传递变量。
{% include "plot.html" with plot=plot only %}
但是你需要从调用view
传递它,否则你可能想要一个标记。
(only
阻止您将整个context
复制到另一个模板