我对 AWS+Django+React 有疑问。我做这个教程https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html .当我写“eb open”时,我遇到了一些麻烦“读取/opt/python/current/app/webpack-stats.json时出错。你确定webpack已经生成了文件并且路径是正确的吗?”。但是,当我在虚拟环境中本地运行项目时,一切正常。
Error 1 image
Error 2 image
我的代码:
设置.py
ALLOWED_HOSTS = ['django-decor-env.ffp8hmcfus.us-west-2.elasticbeanstalk.com', '*']
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['core/templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
STATIC_URL = '/static/'
STATIC_ROOT = "core/staticfiles" - update path.
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'core/static'),
]
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR
# Webpack config
WEBPACK_LOADER = {
'DEFAULT': {
'CACHE': not DEBUG,
'BUNDLE_DIR_NAME': '/', # must end with slash
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
'POLL_INTERVAL': 0.1,
'TIMEOUT': None,
}
}
.exbetensions/python.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: decor/core/wsgi.py
.elasticbeanstalk/django-decor-env.env
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: core/wsgi.py
项目结构Structure
我花了很多时间解决这个问题......任何有用的建议对我来说都会很棒。
更新:
我决定了 S3 的问题,我在主机上查看了我的文件,发现我的文件 webpack-stats.json 没有推送到 AWS。我上传 webpack-stats.json 并重建我的项目,成功编译,但现在我有新问题 Internal Server Error 500
eb logs
背部:mod_wsgi (pid=3438): Target WSGI script
'/opt/python/current/app/core/wsgi.py' cannot be loaded as Python module.
[Tue Jun 12 22:43:17.606738 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
mod_wsgi (pid=3438): Exception occurred processing WSGI script
'/opt/python/current/app/core/wsgi.py'.
[Tue Jun 12 22:43:17.606898 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
Traceback (most recent call last):
[Tue Jun 12 22:43:17.606955 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
File "/opt/python/current/app/core/wsgi.py", line 21, in <module>
[Tue Jun 12 22:43:17.606959 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
application = get_wsgi_application()
[Tue Jun 12 22:43:17.606965 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
File "/opt/python/run/venv/local/lib/python3.6/site
packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Tue Jun 12 22:43:17.606967 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
django.setup(set_prefix=False)
[Tue Jun 12 22:43:17.606972 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
File "/opt/python/run/venv/local/lib/python3.6/site
packages/django/__init__.py", line 19, in setup
[Tue Jun 12 22:43:17.606974 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
我现在做错了什么?谢谢关注。。
最佳答案
我在 AWS 中使用 elasticbeanstalk 的 Django 项目中遇到了同样的错误,对于面临这个问题的任何人,我在多次尝试后解决了这个问题:
WSGIPath: yourApp/wsgi.py
2) 将 Django 降级到 2.1.1 版本,我使用的是不同的 Django,不知何故存在不兼容性。
希望能帮助到你
关于django - AWS 目标 WSGI 脚本 '/opt/python/current/app/core/wsgi.py' 无法作为 Python 模块加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50642163/