我可以使用Django的模板引擎在每个模板标签之后取消换行符吗? [英] Can I suppress newlines after each template tag with Django's template engine?
问题描述
在Rails ERB中,可以通过在标签后添加连字符来取消换行符。
In Rails ERB, you can suppress newlines by adding a trailing hyphen to tags:
<ul>
<% for @item in @items -%>
<li><%= @item %></li>
<% end -%>
</ul>
成为:
<ul>
<li>apple</li>
<li>banana</li>
<li>cacao</li>
</ul>
在Django中有没有办法做到这一点? (公开:我正在使用Django生成一个csv文件)
Is there a way to do this in Django? (Disclosure: I'm generating a csv file with Django)
编辑:澄清了我正在寻找的换行符是模板之后留下的换行符标签。
Clarified that the newlines I'm hunting down are the ones left behind after the template tags.
推荐答案
我找到的与您所寻找的最近的(我正在寻找的)同样的事情)是关于未来的补丁程序,请点击此处: http://code.djangoproject.com/ticket/ 2594 。
The closest I've found to what you're looking for (I'm looking for the same thing) is talk about a future patch, here: http://code.djangoproject.com/ticket/2594.
很遗憾,在他们合并该补丁之前,您似乎无能为力。
Unfortunately, it looks like there's not much you can do until they merge that patch in.
这篇关于我可以使用Django的模板引擎在每个模板标签之后取消换行符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!