Я использую python 3.8 вместе с остальной структурой, и, пожалуйста, найдите приведенные ниже сведения.
Ниже приведен мой сериализатор для пользователей UserSerializer
from django.shortcuts import render
from django.contrib.auth.models import User
from rest_framework import viewsets, status
from rest_framework.response import Response
from rest_framework.decorators import action
from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAuthenticated, AllowAny
from .serializers import MovieSerializer, RatingSerializer, UserSerializer
from .models import Movie, Rating
# Create your views here.
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
urls.py(api component)
router = routers.DefaultRouter()
router.register("movies", MovieViewSet)
router.register("ratings", RatingViewSet)
router.register("users", UserViewSet)
urlpatterns = [
path("", include(router.urls))
]
urls.py(main project)
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include("api.urls")),
path('auth/', obtain_auth_token),
]
Environment:
Request Method: GET
Request URL: http://localhost:8000/api/users/
Django Version: 3.0.8
Python Version: 3.8.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'api',
'corsheaders']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "C:\study\fullstack\Movieraterapi\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\study\fullstack\Movieraterapi\venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\study\fullstack\Movieraterapi\venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\study\fullstack\Movieraterapi\venv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "C:\study\fullstack\Movieraterapi\venv\lib\site-packages\rest_framework\viewsets.py", line 114, in view
return self.dispatch(request, *args, **kwargs)
File "C:\study\fullstack\Movieraterapi\venv\lib\site-packages\rest_framework\views.py", line 488, in dispatch
request = self.initialize_request(request, *args, **kwargs)
File "C:\study\fullstack\Movieraterapi\venv\lib\site-packages\rest_framework\viewsets.py", line 135, in initialize_request
request = super().initialize_request(request, *args, **kwargs)
File "C:\study\fullstack\Movieraterapi\venv\lib\site-packages\rest_framework\views.py", line 390, in initialize_request
authenticators=self.get_authenticators(),
File "C:\study\fullstack\Movieraterapi\venv\lib\site-packages\rest_framework\views.py", line 272, in get_authenticators
return [auth() for auth in self.authentication_classes]
File "C:\study\fullstack\Movieraterapi\venv\lib\site-packages\rest_framework\views.py", line 272, in <listcomp>
return [auth() for auth in self.authentication_classes]
Exception Type: TypeError at /api/users/
Exception Value: 'str' object is not callable
Пожалуйста, помогите мне найти проблему, URL-адреса работают нормально для api/movies/
и api/ratings/
, но когда я пытаюсь доступ к api/users
Я получаю эту ошибку.