Я хочу создать пагинацию в Django?
Это моя кодировка view.py. она работала, но когда я добавил пагинацию, возникла ошибка
def car(request):
all_products = None
all_category = category.get_all_category()
categoryid = request.GET.get('category')
paginator=Paginator(categoryid,4)
page=request.GET.get('page')
try:
all_category.paginator.page(page)
except PageNotAnInteger:
all_category=paginator.page(1)
except EmptyPage:
all_category=paginator.page(paginator.num_pages)
else:
all_category = Product.get_all_products()
if categoryid:
all_products = categoryid.get_all_products_by_id(categoryid)
data = {}
data['products'] = all_products
data['category'] = all_category
all_location = location.get_all_location()
all_products = Product.get_all_products()
all_team = teams.get_all_team_members()
data['product'] = all_products
data['location'] = all_location
data['teams'] = all_team
return render(request, 'car.html', data, {'all_category':all_category,
'categoryid':categoryid,
'category':category(),
'page':page})
**Это мой файл pagination.html **
<div class="">
<span class="">
{% if page.has_previous %}
<a href="?page={{ page.previous_page_number }}">Previous</a>
{% endif %}
<span class="">
Page {{ page.number }} of {{ page.paginator.num_pages }}.
</span>
{% if page.has_next %}
<a href="?page={{ page.next_page_number }}">Next</a>
{% endif %}
</span>
</div>
Это мой файл car.html.
<div class="container-fluid py-1 justify-content-between p-2 m-2">
<div class="container">
<h6 class="display-4 text-uppercase text-center mb-5" style="font-size: 40px">Filters</h6>
{% for category in category %}
<a href="{% url 'car' %}?category={{ category.id }}">
<button type="button" class="btn btn-outline-secondary rounded">{{ category.name }}</button>
</a>
{% endfor %}<hr>
<h1>{% include 'pagination.html' with page=all_category %}</h1>
</div>
</div>
На самом деле я хочу отобразить все данные об автомобилях по пагинации, а также все категории автомобилей по пагинации.
Я следую этому руководству текст
Мой вопрос в том, где я допустил ошибку.
Это ошибка
^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Файл "E:\kashi\CarRental\CarRental\views.py", строка 48, in car all_category.paginator.page(page) ^^^^^^^^^^^^^^^^^^^^^^ AttributeError: объект 'QuerySet' не имеет атрибута 'paginator' [27/Nov/2022 21:50:28] "GET /car/ HTTP/1.1" 500 64248 введите описание изображения здесь