【发布时间】:2015-01-05 14:16:11
【问题描述】:
我使用Python 3.4 + Django 1.7.1 和Eclipse - PyDev,并使用AcroEdit 编辑HTML。
我认为AcroEdit 使用两个软空格进行缩进。
我在custom_tag_library.py 中制作了一个名为custom_tag 的自定义模板标签,例如:
# -*- 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()}
对于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>
(如您所见,内容对象有名称和子项)
所以,custom_tag 是一个递归标签,给出了一个树结构,以<div> 层次结构表示。
但是当我使用它时,输出的 HTML 有很多空格和空行,如下所示:
我试过{% spaceless %}{% endspaceless %},但是没用。
我认为这是因为我使用缩进来增加代码的可读性。但我想保持我对缩进的编码风格。
我该如何解决这个问题?
【问题讨论】: