When I go to this http://127.0.0.1:8000/api/questions/ I get
TypeError at /api/questions/
‘list’ object is not callable
urls.py
(in project)
"""QuestionTime URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.2/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import include, path, re_path from django_registration.backends.one_step.views import RegistrationView from core.views import IndexTemplateView from users.forms import CustomUserForm # https://django-registration.readthedocs.io/en/3.1.2/activation-workflow.html urlpatterns = [ path('admin/', admin.site.urls), path("accounts/register/", RegistrationView.as_view( form_class=CustomUserForm, success_url="/", ), name="django_registration_register"), path("accounts/", include("django_registration.backends.one_step.urls")), path("accounts/", include("django.contrib.auth.urls")), path("api/", include("users.api.urls")), path("api/", include("questions.api.urls")), path("api-auth/", include("rest_framework.urls")), path("api/rest-auth/", include("rest_auth.urls")), path("api/rest-auth/registration/", include("rest_auth.registration.urls")), re_path(r"^.*$", IndexTemplateView.as_view(), name="entry-point"), ]
urls.py
(in appName1/api
from django.urls import include, path from rest_framework import urlpatterns from rest_framework.routers import DefaultRouter from questions.api import views as qv router = DefaultRouter() router.register(r"questions", qv.QuestionViewSet) urlpatterns = [ path("", include(router.urls)), path("questions/<slug:slug>/answers/", qv.AnswerListAPIView.as_view(), name="answer-list"), path("questions/<slug:slug>/answer/", qv.AnswerCreateAPIView.as_view(), name="answer-create"), path("answers/<int:pk>/", qv.AnswerRUDAPIView.as_view(), name="answer-detail"), path("answers/<int:pk>/like/", qv.AnswerLikeAPIView.as_view(), name="answer-like"), ]
views.py
(in appName1/api) Only showing QuestionViewSet
class QuestionViewSet(viewsets.ModelViewSet): queryset = Question.objects.all() lookup_field = "slug" serializer_class = QuestionSerializer permission_classes = [IsAuthenticated, IsAuthorOrReadOnly] def perform_create(self, serializer): serializer.save(author=self.request.user)
From the settings.py
REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.TokenAuthentication', 'rest_framework.authentication.SessionAuthentication', ), 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', ), 'DEFAULT_PAGINATION_CLASS': ( 'rest_framework.pagination.PageNumberPagination', ), 'PAGE_SIZE': 2, }
Error could come from somewhere else.
I don’t know where I can find “list”.
appName1 = questions
Exception Location: lib/python3.9/site-packages/rest_framework/generics.py, line 162, in paginator
Advertisement
Answer
The DEFAULT_PAGINATION_CLASS
setting should be a string not a tuple/list
REST_FRAMEWORK = { ... 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', ... }