【发布时间】:2012-06-23 21:02:17
【问题描述】:
我知道这并不完全是 Django 模板理念,但我希望能够根据我在 http 响应上下文中指定的插件列表包含不同的模板。例如,如果我配置了以下插件:
context['plugins'] = ['weather']
我尝试在基本模板文件中包含每个模板:
{% for custom_plugin in custom_plugins %}
{% include "map/plugins/custom/{{ plugin }}/includes.html" %}
{% endfor %}
我也试过了:
{% for plugin in plugins %}
@register.inclusion_tag("map/plugins/custom/{{ plugin }}/includes.html", takes_context=True)
{% endfor %}
目前,每个插件将仅在其 include.html 文件中包含脚本引用和 css 类:
<script type="text/javascript" src="{{ MEDIA_URL }}map/js/plugins/custom/weather/weatherStation.js?ver={{ version }}"></script>
有什么建议吗?
【问题讨论】:
-
使用标签或变量语法inside标签是从不正确的。
标签: python django templates include