尝试部署 Django 和 WSGI 无法导入我的设置文件 - 配置不正确/模块不存在



我努力不让自己尖叫…

我试图部署我的django项目,我似乎不能正确设置设置模块。我一直在谷歌上搜索,但一无所获。我以前部署过项目(但我仍然是一个新手),没有这个问题,所以我不能弄清楚。请帮助。

我在dotcloud上部署。碰巧我打算在heroku上部署(直到我意识到dotcloud更适合我的项目),并且出现了同样的错误。我就是不知道我做错了什么!

我的设置文件位于:
/Users/<myname>/wheretoeat/wheretoeat/wheretoeat/settings.py

wsgi.py

import os
import sys
#sys.path.append('/Users/<myname>/wheretoeat/wheretoeat/wheretoeat')
from django.core.wsgi import get_wsgi_application
import sys
sys.path.append('/Users/<myname>/wheretoeat/wheretoeat/wheretoeat')
#sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),'wheretoeat')))
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
os.environ["DJANGO_SETTINGS_MODULE"] = "wheretoeat.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wheretoeat.settings")

路径问题有时会有点棘手。我可以建议一种替代方法,通过使用一个工作项目(可靠部署的东西)在dotcloud上启动你的项目,然后增量地将你现有的工作移植到这个基础项目中。我想邀请你看看我们的django-on-dotcloud配方:

https://github.com/dotcloud/django-on-dotcloud

使用这个项目,你应该能够快速迭代一些部署的东西,而不是被一系列可能与部署相关或不相关的问题所困扰(我们不了解你的整个项目,所以很难确定你看到的是什么问题)。模块位置、包位置等可能会影响错误)。

使用这个,你可以看到我们如何设置项目和设置文件的位置。
https://github.com/dotcloud/django-on-dotcloud/blob/master/hellodjango/settings.py

我意识到这个配方有点过时了,而且它没有使用django最新版本中引入的新设置文件位置,但是一旦你有了一个工作项目,你可以逐步使它符合你想要的任何标准。

如果您仍然有问题,请随时给support@dotcloud.com写信,我们可以帮助您仔细查看哪些可能不适合您。

最新更新