我是 django 的新手,想通过简单的 django 应用程序来了解更多信息,在代码中的一个地方,我必须选择locationName
并获取与表中相同locationName
的 id 匹配的元素。当我开始想知道continue
逃避 for 循环的最 Pythonic 方式是什么?
有问题的代码如下:
for locationName in locationGroup:
idRef = locationName.id
try:
element = location.objects.order_by('-id').filter(name__id=idRef)[0]
except IndexError:
continue