Django:错误:配置不当的模块未定义“” ”班级
ImproperlyConfigured:中间件模块“report”未定义“ReportMiddleware”类
但是我已经定义了这个,但可能定义在错误的位置,那么我应该将这个类文件放在哪里?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
今天我遇到了同样的错误。这是由于命名方案令人困惑(至少对我来说)。
如果您像这样指定中间件:
在 settings.py 中并将 SomeMiddleware 类定义放在应用程序目录中的 SomeMiddleware.py 中,您的项目将中断。在这种情况下,settings.py 应为:
更好的方法是对所有中间件定义使用通用的 yourapp/middleware.py 并像 django.contrib 中间件一样使用它,在这种情况下,您的 seetings.py 应包括:
Today I had the same error. It was due to confusing (at least for me) naming scheme.
If you specify your middleware like so:
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:
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:
您应该将其放入
MIDDLEWARE_CLASSES
设置中指定的包中的模块中。You should put it within the module in the package as specified in the
MIDDLEWARE_CLASSES
setting.