我正在开发一个音乐Web应用程序,我试图计算一首歌的播放次数。单击播放按钮时,将调用一个名为的函数。在这里,我尝试使用来更新模型,如下所示。getLink()get_or_createPlayCount
h = PlayCount.objects.all()
if len(h) == 0:
u = PlayCount.objects.get_or_create(
user=request.user.username,
song=song,
plays=1,
)[0]
u.save()
else:
flag = False
for i in h:
if i.song == song:
u = PlayCount.objects.get_or_create(
user=request.user.username,
song=song,
plays=plays + 1,
)[0]
u.save()
flag = True
break
else:
pass
if flag is False:
u = PlayCount.objects.get_or_create(
user=request.user.username,
song=song,
plays=1,
)[0]
u.save()
else:
pass
但是,当我进入 else 循环时,返回 。127.0.0.1:8000play is not defined
我该如何继续?
蝴蝶不菲
相关分类