帮助我理解我的 mod_wsgi Django 配置文件
我想知道为什么这有效:
sys.path.append('/home/user/django')
sys.path.append('/home/user/django/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
但这不起作用?
sys.path.append('/home/user/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
我认为添加 django 文件夹会自动使其中的所有项目/文件夹可供 python 使用?但显然我还必须添加该项目,否则它会给我错误“找不到设置”。
请注意,它没有说“mysite.settings not find”,这表明它确实找到了我的“mysite”文件夹。
I was wondering why this works:
sys.path.append('/home/user/django')
sys.path.append('/home/user/django/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
but this doesn't?
sys.path.append('/home/user/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
I thought that adding the django folder would automatically make all projects/folders in it available to python? But apparantly I have to add the project as well, or it gives me the error 'settings not found'.
Notice that it doesn't say 'mysite.settings not found' which would indicate it does find my 'mysite' folder..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许如果您在 settings.py 中导入了 mysite 目录内的模块,则此导入会失败,这就是您收到 ImportError 的原因。
Maybe if in your settings.py you have an import to a module that's inside the mysite directory, this import fails and that's why you get the ImportError.
看看 http://codespatter.com/2009/04/10/how-to-add-locations-to-python-path-for-reusable-django-apps/
Have a look at http://codespatter.com/2009/04/10/how-to-add-locations-to-python-path-for-reusable-django-apps/