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)修理する。

関連情報