我有一个模型
class tournaments(models.Model): # .... total_rounds = models.IntegerField(max_length=11, blank=True, null=True) # .... def get_total_rounds_count(self): return self.total_rounds
视图.py:
def tourney_view(request, offset): # ..... if (offset): selected_tournament = tournaments.objects.get(id=offset) return render_to_response('tournament.html', {'tournament': selected_tournament})
在“tournament.html”模板中,我尝试遍历total_rounds:
{% for q in tournament.get_total_rounds_count%} {% endfor %}
并得到错误:'long' object is not iterable 为什么?我的字段是 IntegerField,我只是想循环整数值,但得到“不可迭代”