2
我正在Django网站上工作,这是一个生活在this site。我在输出中由于HTML中不需要的空白而导致不需要的空格。Django模板标签创建空间
例如,“01-1737,民间审查权威,不适用的语言,持续”,在大多数逗号之前有额外的空格。
我发现有类似问题的其他帖子,但没有解决方案为我工作。我尝试了{%spaceless%}标记,但那不起作用。我唯一能做的工作就是将所有模板标签放在for循环中,但我真的很想找到比这更可读的解决方案。
下面是Django的模板代码:
{% extends 'police_archive/base.html' %}
{% block content %}
<h2> {{officer.first_name}} {{officer.last_name}}, badge #{{officer.badge}} </h2>
<p><strong>Department:</strong> {{officer.department}}</p>
<h2>Complaints</h2>
<ul>
{% for details in details_list %}
<li>
{% if details.incident.case_number %}
<a href='/police_archive/complaint/{{details.incident.case_number}}'>
{{details.incident.case_number}}
</a>
{% else %}
No Case Number Found
{% endif %}
{% if details.incident.office %}
, {{details.incident.get_office_display}}
{% else %}
, No office found
{% endif %}
{% if details.allegation %}
, {{details.allegation}}
{% endif %}
{% if details.finding %}
, {{details.finding}}
{% endif %}
{% if details.action %}
, {{details.action}}
{% endif %}
</li>
{% endfor %}
{% endblock %}
感谢这个想法。我试图把它搞清楚,然后放弃。这只会导致单个文件出现问题,所以我选择了丑陋的单线解决方案。 –