WSGI下需要的项目*和*应用程序的Django sys.path.append [英] Django sys.path.append for project *and* app needed under WSGI
问题描述
项目base被称为'djapp',应用程序称为'myapp'。
sys.path.append(os.path.dirname (os.path.abspath(__ file__))+'/ ..')
sys.path.append(os.path.dirname(os.path.abspath(__ file__))+'/../djapp' )
os.environ ['DJANGO_SETTINGS_MODULE'] ='djapp.settings'
如果我省略了/../djapp/行,日志告诉我,即使'djapp.settings'是'myapp'无法导入的。 (验证'djapp'被导入)
它使用./manage.py命令正常运行。项目文件夹中有一个 __ init __
。
对于测试,我使用 addsitedir
看到同样的问题:
site.addsitedir('/ home / user / web / project /')
site.addsitedir('/ home / user / web / project / djapp' )
由于 djapp
(django项目文件夹)在父文件夹中,也属于部署我将
djapp
文件夹重命名为 project
。
然后这段代码总是正确:
sys.path.append(os。 path.dirname(os.path.abspath(__ file__))+'/ ..')
sys.path.append(os.path.dirname(os.path.abspath(__ file__))+'/ .. / project')
os.environ ['DJANGO_SETTINGS_MODULE'] ='project.settings'
完整的文件夹布局为:
host.example.com\
etc \\ b $ b bin\
project\
logs\
你有什么。这样的项目总是可以称为项目:)
希望有所帮助。
GrtzG
Could somebody give me a pointer on why I need to add my project root path to the python path as well as the application itself in my WSGI file?
Project base is called 'djapp', the application is called 'myapp'.
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../djapp')
os.environ['DJANGO_SETTINGS_MODULE'] = 'djapp.settings'
If I omit the line with "/../djapp/" the log tells my that 'myapp' can not be imported, even though 'djapp.settings' is. (validating 'djapp' was imported)
It al runs properly with the ./manage.py command. there's a __init__
in the project folder.
For testings sake, I see the same issue using addsitedir
:
site.addsitedir('/home/user/web/project/')
site.addsitedir('/home/user/web/project/djapp')
Since djapp
(the django project folder) is in a parent folder that also belongs to the deployment I renamed the djapp
folder simply to project
.
Then this code is always correct:
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..' )
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../project')
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
The complete folder layout being:
host.example.com\
etc\
bin\
project\
logs\
And what have you. This way project can always be called project :)
Hope that helps.
GrtzG
这篇关于WSGI下需要的项目*和*应用程序的Django sys.path.append的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!