我的编码是: 观点在Django的循环迭代
型号:
class Post(models.Model):
subject = models.CharField(max_length = 250)
body = models.TextField()
thread = models.ForeignKey('self', null = True, editable = False)
Show.html:
{% for post in post_list %}
{{post.id}}{{post.subject}}
{% endfor %}
{% for post_like in post_likes %}
{% if post_like.post_id == post.id and post_like.user_id == user.id %}
U like this post{{post}}
{% else %}
{{post}}
{% endif %}
{% endfor %}
在show.html,其他部分,它会一次又一次显示值。但我只需要一次。当我进入其他条件时,如何打破for循环。请帮助我..
这段代码与Python 2.7.6和Django 1.8.15工作正常。谢谢。 – user3526918