API/serializer.py

API/serializer.py
File "/home/Desktop/booklib/env/lib/python3.8/site-packages/rest_framework/authentication.py", line 126, in authenticate
    self.enforce_csrf(request)
  File "/home/Desktop/booklib/env/lib/python3.8/site-packages/rest_framework/authentication.py", line 135, in enforce_csrf
    check = CSRFCheck()
TypeError: __init__() missing 1 required positional argument: 'get_response'
[21/Dec/2021 14:37:05] "GET /api/ HTTP/1.1" 500 112898

API/serializer.py


from book.models import Book


class BookSerializer(serializers.ModelSerializer):
    class Meta:
        model = Book
        fields = ('title', 'author','summary', 'isbn')```



** Create your views here :api/views.py**


```from django.shortcuts import render
from rest_framework import generics

from book.models import Book
from .serializers import BookSerializer


class BookAPIView(generics.ListAPIView):
    queryset = Book.objects.all()
    serializer_class = BookSerializer```


**# api/urls.py**
```from django.urls import path
from .views import BookAPIView

urlpatterns = [
    path('', BookAPIView.as_view())
]```

답변1

django 4.0으로 업그레이드할 때도 같은 문제가 발생했습니다. Rest_framework를 최신 버전으로 업그레이드하세요(https://github.com/encode/django-rest-framework/releases) 수리하다.

관련 정보