Django在HTML网页上以文本呈现模板标签

时间:2015-02-13 19:05:53

标签: python django templates for-loop

我的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}))

渲染如下:

enter image description here

HTML:

{ % for line in removed %}
    <li>{{ line|safe }}</li>
{ % endfor %}



{ % for line in objection.remove_list %}
    <li>{{ line }}</li>
{ % endfor %}

{{objection.remove_list}}

{{removed}}

1 个答案:

答案 0 :(得分:2)

您模板中的语法有点偏差;删除{%之间的空格:

{% for line in removed %}
    <li>{{ line|safe }}</li>
{% endfor %}



{% for line in objection.remove_list %}
    <li>{{ line }}</li>
{% endfor %}