我有一个模型
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
views.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 %}
出现错误:“长”对象不可迭代 为什么?我的字段是 IntegerField,我只是尝试循环整数值,但得到“不可迭代”
最佳答案
您可以使用以下代码片段:http://djangosnippets.org/snippets/1357/
或者定义Tournament.get_total_rounds
,它返回range(get_total_rounds_count)
关于python - Django: 'long' 对象不可迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11383336/