Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django templates,在for循环中的每个模板标记后抑制换行符_Django_Django Templates - Fatal编程技术网

Django templates,在for循环中的每个模板标记后抑制换行符

Django templates,在for循环中的每个模板标记后抑制换行符,django,django-templates,Django,Django Templates,Django模板系统在for循环中显示列表时添加空行。 尝试呈现此模板时,我有点困惑: <h1>My log</h1> <textarea> {% for item in items %} {{ item }} {% endfor %} </textarea> 我的日志 {items%%中的项的%s} {{item}} {%endfor%} 我期望: <h1>My log</h1> <textarea&

Django模板系统在for循环中显示列表时添加空行。 尝试呈现此模板时,我有点困惑:

<h1>My log</h1>

<textarea>
{% for item in items %}
    {{ item }}
{% endfor %}
</textarea>
我的日志
{items%%中的项的%s}
{{item}}
{%endfor%}
我期望:

<h1>My log</h1>

<textarea>
    * message line of text 1
    * message 
number 2 on multiple lines
    * message line of text 3
</textarea>
我的日志
*文本1的消息行
*信息
多行上的数字2
*文本3的消息行
但我得到了:

<textarea>

    * message line of text 1

    * message 
number 2 on multiple lines

    * message line of text 3

</textarea>

*文本1的消息行
*信息
多行上的数字2
*文本3的消息行

是否有某种方法可以抑制空行并获得所需的结果?

找到了简单的解决方案:

<textarea>
{% for item in items %}   {{ item }}
{% endfor %}</textarea>

{%for items%}{{item}中的项
{%endfor%}

找到了简单的解决方案:

<textarea>
{% for item in items %}   {{ item }}
{% endfor %}</textarea>

{%for items%}{{item}中的项
{%endfor%}

我相信您正在寻找
{%spaceless%}
标记:


{%spaceless%}
{items%%中的项的%s}
{{item}}
{%endfor%}
{%endspaceless%}
但请注意,仅删除标记之间的空格,因此您可能需要:

<textarea>
{% spaceless %}
    {% for item in items %}{{ item }}{% endfor %}
{% endspaceless %}
</textarea>

{%spaceless%}
{%for items%}{{item}{%endfor%}
{%endspaceless%}
事实上,以下内容实际上可能会为您提供帮助:

<textarea>
    {% for item in items %}{{ item }}{% endfor %}
</textarea>

{%for items%}{{item}{%endfor%}

如果您的
元素实际上包含换行符,则您需要在使用筛选器或模型方法或其他方法之前以某种方式将其剥离。

我相信您正在寻找
{%spaceless%}
标记:


{%spaceless%}
{items%%中的项的%s}
{{item}}
{%endfor%}
{%endspaceless%}
但请注意,仅删除标记之间的空格,因此您可能需要:

<textarea>
{% spaceless %}
    {% for item in items %}{{ item }}{% endfor %}
{% endspaceless %}
</textarea>

{%spaceless%}
{%for items%}{{item}{%endfor%}
{%endspaceless%}
事实上,以下内容实际上可能会为您提供帮助:

<textarea>
    {% for item in items %}{{ item }}{% endfor %}
</textarea>

{%for items%}{{item}{%endfor%}

如果您的
元素实际上包含换行符,那么您需要在使用筛选器或模型方法或其他方法之前以某种方式将其剥离。

最初,我使用循环模板来迭代日志行。我想在textarea中显示日志消息。最初,我使用模板中的循环来迭代日志行。我想在textarea中显示日志消息。它比任何其他解决方案都好!ThanksWorks比任何其他解决方案都好!谢谢