django,多个数据库,配置问题:“导入数据库路由器时出错”
我已按照 这些说明 设置 Django多个数据库。它在我的本地开发环境(win7)中按预期工作,但是,当我将项目上传到我的实时服务器(webfaction)时,我得到了
ImproperlyConfigured: 导入数据库路由器 MyCustomRouter 时出错:“没有名为 path.to.my.router 的模块”
从 Django shell,我可以导入 MyCustomRouter:
>>> from path.to.my.router import MyCustomRouter
>>>
我在本地和实时服务器上运行 django 1.2.1 和 python2.6 ...
任何非常感谢提示可能导致此行为的原因或如何调试!
干杯,
马丁
I've followed these instructions to set up Django with multiple databases. It's working as intended in my local dev environment (win7), however, when I upload the project to my live server (webfaction), I get
ImproperlyConfigured:
Error importing database router MyCustomRouter: "No module named path.to.my.router"
From the Django shell, I can import MyCustomRouter:
>>> from path.to.my.router import MyCustomRouter
>>>
I'm running django 1.2.1 and python2.6 both locally and on live server...
Any hints what could be causing this behavior or how to debug are be greatly appreciated!
Cheers,
Martin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我也有同样的问题。我在 models.py 中定义了一个路由器。将类定义移动到它自己的文件中(我将其命名为 router.py),并相应地更新 settings.py,解决了错误。
I had the same problem. I had defined a router in models.py. Moving the class definition into its own file (I named mine router.py), and updating settings.py accordingly, resolved the error.
path.to.myrouter
只是一个占位符。path.to.myrouter
is just a placeholder.只需将以下内容添加到您的setting.py文件中
,重命名您的路由器文件routers.py
Just add the following to your setting.py file
rename your router file routers.py
示例:
我的项目由多个应用程序组成,例如“工资”、“税务”、“帮助台”等。
我在这里使用 2 db - 默认和 prod_db
这就是我设置路由器路径的方式,
1.在薪资应用程序中,我创建了“drouter.py”文件
2.在 dbrouter.py 中,我定义了 DbRouter 类(请参阅此路由器代码 - https://docs.djangoproject.com/en/2.1/topics/db/multi-db/)
3.在settings.py中设置路径
DATABASE_ROUTERS = ['payroll.dbrouter.DbRouter',]
Example:
My projects consists of multiple apps like 'payroll', 'taxation', 'helpdesk' etc.
I am using 2 db here - default and prod_db
This is how i set router path,
1. In payroll app i created "dbrouter.py" file
2. In dbrouter.py, i define DbRouter class (refer this for router code - https://docs.djangoproject.com/en/2.1/topics/db/multi-db/)
3. In settings.py, path is set
DATABASE_ROUTERS = ['payroll.dbrouter.DbRouter',]