我正在使用在Elastic Beanstalk的64位Amazon Linux / 2.7.7上运行的Python 3.6。
这是我的文件结构:
- analytics
-- (a bunch of files that I think are irrelevant here)
- db.sqlite3
- ecs_site
-- __init__.py
-- __pycache__
-- settings.py
-- static
-- css
-- (a bunch of files - important)
-- fonts
-- (a bunch of files - important)
-- images
-- (a bunch of files - important)
-- templates
-- (a bunch of files that I think are irrelevant here)
-- urls.py
-- wsgi.py
- manage.py
- pages
-- (a bunch of files that I think are irrelevant here)
- requirements.txt
在settings.py文件中,内容如下:
#STATIC_ROOT = os.path.dirname(__file__)
STATIC_ROOT = os.path.join(BASE_DIR, "ecs_site", "static")
#SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
#STATICFILES_DIRS = [os.path.join(SITE_ROOT, 'static/')]
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_URL = '/static/'
#STATICFILES_DIRS = [os.path.join(BASE_DIR, 'ecs_site/static/'), os.path.join(BASE_DIR, 'ecs_site/static/images/'),
#os.path.join(BASE_DIR, 'ecs_site/static/fonts/'), os.path.join(BASE_DIR, 'ecs_site/static'), os.path.join(BASE_DIR, 'ecs_site/static/images'),
#os.path.join(BASE_DIR, 'ecs_site/static/fonts')]
#STATICFILES_DIRS = [os.path.join(BASE_DIR, '/static/'), os.path.join(BASE_DIR, '/static/images/'),
#os.path.join(BASE_DIR, '/static/fonts/'), os.path.join(BASE_DIR, '/static'), os.path.join(BASE_DIR, '/static/images'),
#os.path.join(BASE_DIR, '/static/fonts')]
在配置文件中,这就是我所拥有的(在AWS EB控制台中设置):
答案 0 :(得分:0)
解决此问题的方法是查看ecs_site
目录。如果运行命令ls -lhra
,它将显示一个名为.ebextensions
的隐藏目录。在该文件夹中创建一个名为django.config
的文件(如果不存在)。在该文件中,我包含以下代码:
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTING_MODULE: "ecs_site.settings"
PYTHONPATH: "/opt/python/current/app/ecs_site:$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: "ecs_site/ecs_site/wsgi.py"
那解决了问题。我不知道为什么会这样,但是确实有用。