我的django HTML标签在通过" for"运行它们时不起作用。环。如果我打印出变量,它会输出普通列表。我甚至尝试了不同的方式来分配变量。发生了什么?
view.py
class CheckbackView(View):
def post(self, request):
statusly = request.POST.get("ConfigSubmit", "")
list_init_config = statusly.splitlines()
with open('/data/test.txt', 'w') as fout:
fout.write(statusly)
fout.close()
converted = Con1812_to_891(statusly)
converted_config = converted.config
removed_list = converted.remove_list
return render(request, 'thunderdome/compare_edit.html', context_instance = RequestContext(request, {'config': statusly, 'converted': converted.config, 'removed': removed_list, 'objection': converted}))
渲染如下:
HTML:
{ % for line in removed %}
<li>{{ line|safe }}</li>
{ % endfor %}
{ % for line in objection.remove_list %}
<li>{{ line }}</li>
{ % endfor %}
{{objection.remove_list}}
{{removed}}
答案 0 :(得分:2)
您模板中的语法有点偏差;删除{
和%
之间的空格:
{% for line in removed %}
<li>{{ line|safe }}</li>
{% endfor %}
{% for line in objection.remove_list %}
<li>{{ line }}</li>
{% endfor %}