Python /api/questions/'处的类型错误;列表';对象不可调用(Django)
当我去的时候,我得到了 在/api/questions/ “列表”对象不可调用 url.py (项目中) url.py (在appName1/api中)Python /api/questions/'处的类型错误;列表';对象不可调用(Django),python,django,django-rest-framework,typeerror,Python,Django,Django Rest Framework,Typeerror,当我去的时候,我得到了 在/api/questions/ “列表”对象不可调用 url.py (项目中) url.py (在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
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"),
]
从settings.py
错误可能来自其他地方
我不知道在哪里可以找到“名单”
appName1=问题
异常位置:分页器中的lib/python3.9/site-packages/rest\u framework/generics.py,第162行
REST_FRAMEWORK = {
...
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
...
}
您可以将视图集的代码添加到问题中吗?
classquestionviewset(viewsets.ModelViewSet):queryset=question.objects.all()lookup\u field=“slug”serializer\u class=QuestionSerializer权限\u classes=[IsAuthenticated,IsAuthorReadOnly]def perform\u create(self,serializer):serializer.save(author=self.request.user)
要在views.py中查找代码,它位于顶部。错误来自您发布的代码的位置不明显。您能否将完整的回溯添加到您的问题中,并删除所有与错误无关的代码,因为它只是添加了错误noise@IainShelvington您需要查看哪些文件?错误的完整回溯将是最有用的保险商实验室
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)
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,
}
REST_FRAMEWORK = {
...
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
...
}