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)
JavaScript
x
50
50
1
"""QuestionTime URL Configuration
2
3
The `urlpatterns` list routes URLs to views. For more information please see:
4
https://docs.djangoproject.com/en/3.2/topics/http/urls/
5
Examples:
6
Function views
7
1. Add an import: from my_app import views
8
2. Add a URL to urlpatterns: path('', views.home, name='home')
9
Class-based views
10
1. Add an import: from other_app.views import Home
11
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12
Including another URLconf
13
1. Import the include() function: from django.urls import include, path
14
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15
"""
16
from django.contrib import admin
17
from django.urls import include, path, re_path
18
19
from django_registration.backends.one_step.views import RegistrationView
20
21
from core.views import IndexTemplateView
22
from users.forms import CustomUserForm
23
24
# https://django-registration.readthedocs.io/en/3.1.2/activation-workflow.html
25
26
urlpatterns = [
27
path('admin/', admin.site.urls),
28
29
path("accounts/register/", RegistrationView.as_view(
30
form_class=CustomUserForm,
31
success_url="/",
32
), name="django_registration_register"),
33
34
path("accounts/", include("django_registration.backends.one_step.urls")),
35
36
path("accounts/", include("django.contrib.auth.urls")),
37
38
path("api/", include("users.api.urls")),
39
40
path("api/", include("questions.api.urls")),
41
42
path("api-auth/", include("rest_framework.urls")),
43
44
path("api/rest-auth/", include("rest_auth.urls")),
45
46
path("api/rest-auth/registration/", include("rest_auth.registration.urls")),
47
48
re_path(r"^.*$", IndexTemplateView.as_view(), name="entry-point"),
49
]
50
urls.py
(in appName1/api
JavaScript
1
21
21
1
from django.urls import include, path
2
from rest_framework import urlpatterns
3
from rest_framework.routers import DefaultRouter
4
5
from questions.api import views as qv
6
7
router = DefaultRouter()
8
router.register(r"questions", qv.QuestionViewSet)
9
10
urlpatterns = [
11
path("", include(router.urls)),
12
13
path("questions/<slug:slug>/answers/", qv.AnswerListAPIView.as_view(), name="answer-list"),
14
15
path("questions/<slug:slug>/answer/", qv.AnswerCreateAPIView.as_view(), name="answer-create"),
16
17
path("answers/<int:pk>/", qv.AnswerRUDAPIView.as_view(), name="answer-detail"),
18
19
path("answers/<int:pk>/like/", qv.AnswerLikeAPIView.as_view(), name="answer-like"),
20
]
21
views.py
(in appName1/api) Only showing QuestionViewSet
JavaScript
1
9
1
class QuestionViewSet(viewsets.ModelViewSet):
2
queryset = Question.objects.all()
3
lookup_field = "slug"
4
serializer_class = QuestionSerializer
5
permission_classes = [IsAuthenticated, IsAuthorOrReadOnly]
6
7
def perform_create(self, serializer):
8
serializer.save(author=self.request.user)
9
From the settings.py
JavaScript
1
14
14
1
REST_FRAMEWORK = {
2
'DEFAULT_AUTHENTICATION_CLASSES': (
3
'rest_framework.authentication.TokenAuthentication',
4
'rest_framework.authentication.SessionAuthentication',
5
),
6
'DEFAULT_PERMISSION_CLASSES': (
7
'rest_framework.permissions.IsAuthenticated',
8
),
9
'DEFAULT_PAGINATION_CLASS': (
10
'rest_framework.pagination.PageNumberPagination',
11
),
12
'PAGE_SIZE': 2,
13
}
14
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
JavaScript
1
6
1
REST_FRAMEWORK = {
2
3
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
4
5
}
6