返回

python-如何在我的代码中添加 Page?django

发布时间:2022-07-27 05:56:28 259
# node.js

我想在我的代码中添加分页功能。这个 socre_by 函数按分数排列。但是很多电影和电视排队。我想分页电影和电视。如何在保留此代码功能的同时添加分页功能?

def Score_by(request):
    query_min = 0
    query_max = 10
    if request.GET.get('min') and request.GET.get('max'):
        query_min = request.GET.get('min')
        query_max = request.GET.get('max')
    movies = Movie.objects.order_by('-stars')
    movie_list= []
    Ranking = 1
    if movies.exists():
        for obj in movies:
            if (float(query_min) <= float(obj.average_stars())) and (float(query_max) >= float(obj.average_stars())):
                data = requests.get(f"https://api.themoviedb.org/3/movie/{obj.id}?api_key={TMDB_API_KEY}&language=en-US")
                data_movie = data.json()
                data_movie['score'] = obj.average_stars()
                data_movie['Ranking'] = Ranking
                movie_list.append(data_movie)
                Ranking += 1
           # print(movie_list)
    tv = TV.objects.order_by('-stars')
    tv_list = []
    Ranking = 1
    if tv.exists():
        for obj in tv:
            if (float(query_min) <= float(obj.average_stars())) and (float(query_max) >= float(obj.average_stars())):
                data = requests.get(f"https://api.themoviedb.org/3/tv/{obj.id}?api_key={TMDB_API_KEY}&language=en-US")
                data_tv = data.json()
                data_tv['score'] = obj.stars
                data_movie['Ranking'] = Ranking
                tv_list.append(data_tv)
                Ranking += 1
    context = {
        'movie':movie_list,
        'tv'   :tv_list
    }
    return render(request, 'Movie/score_by.html', context)
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(1)
按点赞数排序
用户头像