Django模板标记看不到范围变量

时间:2019-11-29 13:22:51

标签: angularjs django django-templates angularjs-scope

我正在尝试动态包含基于AngularJS作用域变量的Django模板。变量包含字符串格式的“图像”,“音频”或“视频”值。我正在使用'with'标签和'add'过滤器来获取模板路径和名称,例如“ record / audio.html”:

{% with template_name=record.filetype|add:".html" %}
    {% include "record/"|add:template_name %}
{% endwith %}

不幸的是,我最终收到错误消息:“ TemplateDoesNotExist /record/.html”。即使我尝试使用[[record.filetype]]进行打印,该变量似乎也不存在。

我猜想在执行'with / include'标签时还没有加载范围。我在'main'html标记中用'ng-init'加载了作用域,我不确定这是最佳实践,但我不知道该怎么做。

<main ng-controller="ProjectCtrl" ng-init="getRecord('{{ project }}')" ng-cloak>

{% with template_name=record.filetype|add:".html" %}
    {% include "record/"|add:template_name %}
{% endwith %}

<!-- some other code -->

0 个答案:

没有答案