在Amazon Elastic Beanstalk上部署Django,未设置LOGGING_INFO环境变量

unhi4e5o  于 2023-03-20  发布在  Go
关注(0)|答案(2)|浏览(108)

我成功地在Elastic Beanstalk上部署了Django(1.7),但是当我在浏览器中加载它时,我得到了500。

[Wed Sep 24 12:56:11.434509 2014] [:error] [pid 27030] [remote 172.31.6.176:0] mod_wsgi (pid=27030): Target WSGI script '/opt/python/current/app/mysite/wsgi.py' cannot be loaded as Python module.
[Wed Sep 24 12:56:11.434557 2014] [:error] [pid 27030] [remote 172.31.6.176:0] mod_wsgi (pid=27030): Exception occurred processing WSGI script '/opt/python/current/app/mysite/wsgi.py'.
[Wed Sep 24 12:56:11.434596 2014] [:error] [pid 27030] [remote 172.31.6.176:0] Traceback (most recent call last):
[Wed Sep 24 12:56:11.434636 2014] [:error] [pid 27030] [remote 172.31.6.176:0]   File "/opt/python/current/app/mysite/wsgi.py", line 14, in <module>
[Wed Sep 24 12:56:11.434698 2014] [:error] [pid 27030] [remote 172.31.6.176:0]     application = get_wsgi_application()
[Wed Sep 24 12:56:11.434721 2014] [:error] [pid 27030] [remote 172.31.6.176:0]   File "/opt/python/run/venv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Wed Sep 24 12:56:11.434759 2014] [:error] [pid 27030] [remote 172.31.6.176:0]     django.setup()
[Wed Sep 24 12:56:11.434781 2014] [:error] [pid 27030] [remote 172.31.6.176:0]   File "/opt/python/run/venv/lib/python2.7/site-packages/django/__init__.py", line 20, in setup
[Wed Sep 24 12:56:11.434813 2014] [:error] [pid 27030] [remote 172.31.6.176:0]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Wed Sep 24 12:56:11.434835 2014] [:error] [pid 27030] [remote 172.31.6.176:0]   File "/opt/python/run/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
[Wed Sep 24 12:56:11.434867 2014] [:error] [pid 27030] [remote 172.31.6.176:0]     self._setup(name)
[Wed Sep 24 12:56:11.434886 2014] [:error] [pid 27030] [remote 172.31.6.176:0]   File "/opt/python/run/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
[Wed Sep 24 12:56:11.434916 2014] [:error] [pid 27030] [remote 172.31.6.176:0]     % (desc, ENVIRONMENT_VARIABLE))
[Wed Sep 24 12:56:11.435013 2014] [:error] [pid 27030] [remote 172.31.6.176:0] ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

我在我的.ebextension mysite.config文件中设置设置文件,如下所示。

- option_name: DJANGO_SETTINGS_MODULE
    value: "mysite.settings"

我还在大多数文件中添加了以下内容:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

问题是我的设置文件应该是什么样子的。我已经在谷歌上搜索了好几个小时了,但是我不能让它工作......我甚至不知道我的设置文件应该是什么样子的。现在它看起来就像这样:

LOGGING_CONFIG = 'django.utils.log.dictConfig'

我很肯定问题出在设置文件上。如果有人能给我指出正确的方向,我将非常感激。

ct3nt3jp

ct3nt3jp1#

我还在大多数文件中添加了以下内容:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
这段代码只需要放在你的.wsgi文件中,它在其他地方没有用。
现在,完成这些操作后,下面是setdefault方法不执行与手动赋值相同的操作的原因:
关键问题是setdefault()方法在设置环境变量DJANGO_SETTINGS_MODULE时的作用,与之前使用赋值相比。在赋值的情况下,环境变量总是更新的。对于setdefault(),它只在尚未设置时更新。
通过this。希望这能说明问题。

8i9zcol2

8i9zcol22#

所以在尝试了所有的东西之后,我最终加载了Django样例项目。我修改了这一行:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

到这一行

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

在wsgi.py中。
为什么它现在起作用了?

相关问题