shaare.it

TypeError: __init__() missing 1 required positional argument: 'request'

7 Dec 2025

1 min read

TypeError: init missing request

$ python - <<'PY'
class V:
    def __init__(self, request): pass
V()
PY
Traceback (most recent call last):
TypeError: __init__() missing 1 required positional argument: 'request'

Why this happens

You instantiate a CBV directly instead of routing through as_view(), which constructs the view and passes request when called.

Fix

Use MyView.as_view() in URL patterns.

Wrong code

urlpatterns = [
    path('x/', MyView()),
]

Fixed code

urlpatterns = [
    path('x/', MyView.as_view()),
]