稍微优化了下
# 文章首页 def get_index_page(request): page = int(request.GET.get('page')) if page: page = page else: page = 1 article_list = Article.objects.all() p = Paginator(article_list, 1) print(len(article_list)) page_list = p.page(page) return render(request, 'blog/index.html', { 'article_list': page_list, 'page_num': range(1, p.num_pages + 1), 'previous_page': page - 1, 'next_page': page if page >= len(article_list) else page + 1, })