我遇到过类似的问题,但无法找到我的问题的解决方案。我有 4 张卡(电影卡),前两张运行良好,但其余的则不行。一旦我向 views.py 添加了一些逻辑,以便根据给出的评论显示每部电影的平均评分,问题就开始出现了。 这是views.py中的代码
def detail(request, id):
movie = Movie.objects.get(id=id)
reviews = Review.objects.filter(movie=id).order_by('-comment')
average = reviews.aggregate(Avg('rating'))["rating__avg"]
average = round(average, 1)
# The problem is above(in round) but dunno how to fix it
context = {'movie': movie, 'reviews': reviews, 'average': average}
return render(request, 'detail.html', context)