MiddlewareMixin отсутствует необходимый аргумент: 'get_response' django

Есть ли у кого-нибудь идеи, почему я получаю эту ошибку? Моя программа работала раньше, и я не знаю, что я изменил, чтобы вызвать ее поломку.

Мой основной сайт работает, но всякий раз, когда я делаю этот get запрос к http://10.0.0.233:8000/watcher/form/list я получаю ошибку, описанную ниже. Я просмотрел весь свой проект и не нашел нигде использования MiddlewareMixin.

urls.py:

from django.urls import path
from . import views

urlpatterns = [
    path('form/list',views.get_all_form_items),
]

Views.py

@api_view(['GET'])
def get_all_form_items(request):
    snippets = form_item_db.objects.all()
    serializer = form_item_db_serializer(snippets, many=True)
        
    return Response(serializer.data)

Ошибка:

Django version 4.0, using settings 'backend.settings'
Starting development server at http://10.0.0.233:8000/
Quit the server with CTRL-BREAK.
[05/Jan/2022 02:11:55] "GET /watcher HTTP/1.1" 200 644
[05/Jan/2022 02:11:55] "GET /static/js/main.1924b030.js HTTP/1.1" 304 0
[05/Jan/2022 02:11:55] "GET /static/css/main.31d6cfe0.css HTTP/1.1" 304 0
Internal Server Error: /watcher/form/list
Traceback (most recent call last):
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\django\views\generic\base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 505, in dispatch
    response = self.handle_exception(exc)
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 465, in handle_exception
    self.raise_uncaught_exception(exc)
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 476, in raise_uncaught_exception
    raise exc
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 493, in dispatch
    self.initial(request, *args, **kwargs)
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 410, in initial
    self.perform_authentication(request)
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 324, in perform_authentication
    request.user
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\request.py", line 220, in user
    self._authenticate()
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\request.py", line 373, in _authenticate
    user_auth_tuple = authenticator.authenticate(self)
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\authentication.py", line 126, in authenticate
    self.enforce_csrf(request)
  File "C:\Users\bestg\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\authentication.py", line 135, in enforce_csrf
    check = CSRFCheck()
TypeError: MiddlewareMixin.__init__() missing 1 required positional argument: 'get_response'

есть исправление в пакете DRF на github начиная с версии 10.2020: https://github.com/encode/django-rest-framework/commit/7921e9af434f2ccfde6962cf8a1b76331cc77722#diff-25717930a68aebbdb51ee5f4060fb1e756d65ee4e8d96faf8ad614ceced0db05

rest_framework/authentication.py в районе строки 139

check = CSRFCheck()

изменяется на

def dummy_get_response(request):  # pragma: no cover
    return None

check = CSRFCheck(dummy_get_response)

Back to Top