Django 1.11.4
以下是DTL。
你能看一下下面的追溯吗? 这个问题与" | add:container_classes"有关。 如果我删除它,模板就不会爆炸。
好吧,我试验过:
嗯,实验有效:渲染模板。并且打印变量。 容器上了班级" abracadabra"。
稍后添加:
并且实验2工作正常。我的意思是一切都好:没有错误, 像预期的那样将类添加到html中。
你能帮我一把吗?
模板
{% include 'general/inclusions/container/container_block_begin.html' with id_suffix=id classes="margin-top-10 margin-left-10 "|add:container_classes %}
...something
{% include 'general/inclusions/container/container_block_end.html' with id_suffix=id%}
回溯
VariableDoesNotExist at /frames/2/
Failed lookup for key [container_classes] in "[{'True': True, 'False': False, 'None': None}, {}, {}, {'object': <Frame: 2>, 'frame': <Frame: 2>, 'view': <frames.views.FrameDetailView object at 0x7fef6647fcf8>}]"
实验
{{ container_classes }}
{% include 'general/inclusions/container/container_block_begin.html' with id_suffix=id classes="margin-top-10 margin-left-10 "|add:"abracadabra" %}
...something
{% include 'general/inclusions/container/container_block_end.html' with id_suffix=id%}
experiment_2
{% with container_classes=container_classes %}
{% include 'general/inclusions/container/container_block_begin.html' with id_suffix=id classes="margin-top-10 margin-left-10 "|add:container_classes %}
...something
{% include 'general/inclusions/container/container_block_end.html' with id_suffix=id%}
{% endwith %}