5

ImproperlyConfigured: Middleware module "report" does not define a "ReportMiddleware" class

But I had defined this, but probably defined in wrong place, so where should I place this class file?

2 Answers 2

18

Today I had the same error. It was due to confusing (at least for me) naming scheme.

If you specify your middleware like so:

'yourapp.SomeMiddleware'

in your settings.py and put your SomeMiddleware class definition in SomeMiddleware.py in your application directiory your project will break. In this case settings.py should read:

'yourapp.SomeMiddleware.SomeMiddleware'

a better method would be to use a common yourapp/middleware.py for all middleware definitions and use it like django.contrib middlewares do, in which case your seetings.py should include:

'yourapp.middleware.SomeMiddleware'
Sign up to request clarification or add additional context in comments.

Comments

1

You should put it within the module in the package as specified in the MIDDLEWARE_CLASSES setting.

3 Comments

Yes, I did this in settings.py
That's nice. Is it in the module in the package specified?
Found the issue, sorry, my bad.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.