Django REST Framework pagination: Not found: GET /api/blog/list HTTP/1.1" 404 0

456 views Asked by At

I am trying to implement simple pagination using Django rest frame work. But I am getting Status 404 Not Found in Postman. Custom urls.py included from base urls.py Base urls.py

urlpatterns = [
...
    path('api/blog/', include('item.api.urls', 'item-api-name')),
...

url.py used in include() mentioned above

from django.urls import path

from item.api.views import (
    api_detail_item_view,
    api_create_item_view,
    ApiBlogListView
)

app_name = 'item'
urlpatterns = [
    path('<slug_from_api_url>', api_detail_item_view, name="item_detail_api"),
    path('create_api/', api_create_item_view, name="item_create_api"),
    path('list', ApiBlogListView.as_view(), name="list"),

]

serializers.py file:

from rest_framework import serializers
from item.models import ItemMaint

class ItemMaintSerializer(serializers.ModelSerializer):
    class Meta:
        model = ItemMaint
        fields = ['name', 'itemDescription', 'active', 'slug']

views.py file:

class ApiBlogListView(ListAPIView):
    queryset = ItemMaint.objects.all()
    serializer_class = ItemMaintSerializer
    pagination_class = PageNumberPagination

Settings.py file

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 1,
}

Thanks in advance.

1

There are 1 answers

0
Milan On

Appended / in the custom urls.py file. Changed from

 path('list', ApiBlogListView.as_view(), name="list"),

to

 path('list/', ApiBlogListView.as_view(), name="list"),