gpt4 book ai didi

python - Django:部署到 ElasticBeanstalk myapp.settings 上导入错误

转载 作者:行者123 更新时间:2023-11-30 22:59:14 25 4
gpt4 key购买 nike

我正在将一个应用程序部署到 ElasticBeanstalk,但遇到了一个看似非常简单的障碍。该错误实际上是ImportError:没有名为 myapp.settings 的模块,但我无法弄清楚是什么导致了此问题。我过去部署过具有相同设置的其他 django 应用程序,但以前没有遇到过此问题。

我在下面附上了来自 eb 的错误日志以及我的 manage.py 和 .ebextensions 文件

eb 日志中的错误

[2016-03-07T03:10:29.648Z] INFO  [3559]  - [Application update/AppDeployStage0/EbExtensionPostBuild] : Starting activity...
[2016-03-07T03:10:30.852Z] INFO [3559] - [Application update/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Starting activity...
[2016-03-07T03:10:30.853Z] INFO [3559] - [Application update/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_Myapp] : Starting activity...
[2016-03-07T03:10:31.824Z] INFO [3559] - [Application update/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_Myapp/Command 01_collectstatic] : Starting activity...
[2016-03-07T03:10:31.894Z] INFO [3559] - [Application update/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_Myapp/Command 01_collectstatic] : Activity execution failed, because: Traceback (most recent call last):
File "Myapp/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named myapp.settings
(ElasticBeanstalk::ExternalInvocationError)

manage.py

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Sifhub.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)

.ebextensions/01-django_eb.config

option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "Myapp.settings"
PYTHONPATH: "/opt/python/current/app/Myapp:$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: "Myapp/Myapp/wsgi.py"
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "subapp/static/"

最佳答案

我看到您的 django 应用程序名称是 Sifhub 并且您的配置文件内容 Myapp 作为您的应用程序名称。

你的配置文件理想情况下应该是这样的:

option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "Sifhub.settings"
PYTHONPATH: "/opt/python/current/app/Sifhub:$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: "Sifhub/wsgi.py"
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "subapp/static/"

关于python - Django:部署到 ElasticBeanstalk myapp.settings 上导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35836106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com