[英]I can't figure out how to serve Static Files using AWS Elasticbeanstalk
我正在使用在 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 控制台中设置):
解决此问题的方法是查看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"
这解决了问题。 我不知道确切原因,但它奏效了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.