I use Python 3.4
+ Django 1.7.1
with Eclipse - PyDev
我用AcroEdit
编辑 HTML。
I think AcroEdit
使用两个软空格进行缩进。
我制作了一个名为的自定义模板标签custom_tag
in custom_tag_library.py
like:
# -*- coding: utf-8 -*-
from django import template
from _ast import Num
register = template.Library()
@register.inclusion_tag('custom_tag.html')
def custom_tag(content):
return {'content': content, 'children': content.children.all()}
and for custom_tag.html
:
{% load custom_tag_library %}
<div class = 'a'>
{{ content.name }}
{% if children %}
<div class = 'b'>
{% for child in children %}
{% custom_tag child %}
{% endfor %}
</div>
{% endif %}
</div>
(如您所见,内容对象有名称和子对象)
So, custom_tag
是一个递归标签,给出了表示为的树结构<div>
等级制度。
但是当我使用它时,输出的 HTML 有很多空格和空行,如下所示:
I tried {% spaceless %}
{% endspaceless %}
,但它不起作用。
我认为出现这种情况是因为我使用缩进来提高代码的可读性。但我想保持我关于缩进的编码风格。
我怎样才能解决这个问题?