The problem
Think about what will get rendered when sub.name == 'all'
- the <div>
is currently outside the if tag, so was getting displayed regardless. You'll get this:
<div class="post">
</div>
This is probably why you're getting an extra line.
The solution
Move the <div>
inside your if tag:
{% for sub in subreddits %}
{% if sub.name != 'all' %}
<div class="post">
<a href="{% url 'sub_detail' pk=sub.pk %}">{{ sub.name }}</a>
</div>
{% endif %}
{% endfor %}
This way when sub.name == 'all'
, nothing is rendered at all.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…