Django: Error: ImproperlyConfigured Module does not define a “ ” class

最后都变了- 提交于 2019-12-06 05:06:23

问题


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?


回答1:


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




回答2:


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'


来源:https://stackoverflow.com/questions/4048618/django-error-improperlyconfigured-module-does-not-define-a-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!