ImproperlyConfigured: Middleware not found in settings
ImproperlyConfigured: Middleware not found in settings
$ python manage.py runserver
...
ImportError: Could not import middleware 'myapp.middleware.Custom': Module not found
Why this happens
You listed a middleware path that doesn’t exist or has a typo, or the module isn’t importable.
Fix
Correct the dotted path and ensure the class is defined and importable.
Wrong code
MIDDLEWARE = [
'myapp.middlewares.Custom', # typo and wrong module
]
Fixed code
MIDDLEWARE = [
'myapp.middleware.CustomMiddleware',
]
# myapp/middleware.py
class CustomMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
return self.get_response(request)