Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Error: ImproperlyConfigured Module does not define a " " class

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?

like image 709
user469652 Avatar asked Dec 03 '22 10:12

user469652


2 Answers

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'
like image 54
Can Kavaklıoğlu Avatar answered Dec 26 '22 20:12

Can Kavaklıoğlu


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

like image 32
Ignacio Vazquez-Abrams Avatar answered Dec 26 '22 20:12

Ignacio Vazquez-Abrams