我的编码是:视图
def showThread(request, thread_id)
post_list = Post.objects.filter(id = thread_id)
post_likes = PostLikes.objects.all()
return render_to_response('show.html',locals(),context_instance=RequestContext(request))
楷模:
class Post(models.Model):
subject = models.CharField(max_length = 250)
body = models.TextField()
thread = models.ForeignKey('self', null = True, editable = False )
显示.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, else 部分,它一次又一次地显示值。但我只需要一次。当我进入 else 条件时如何打破 for 循环。请帮助我..