Amazon Web Service(AWS)上的Django [英] Django on Amazon Web Service (AWS)
问题描述
我已阅读这些教程: https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/ 和 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
I have read these tutorials : https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/ and http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
我使用Django 1.8.2,似乎amazon的文档有点过时(他们仍然使用django-admin.py而不是django-管理员),并且它的一些部分是不工作的(当东西不起作用,我回到真实的链接一)。
I use Django 1.8.2 and it seems that the amazon's doc is a little bit outdated (they still used django-admin.py instead of django-admin), and some parts of it are not working (when stuff does not work, i fallback to the realpython link one).
所以,除非我的管理页面没有加载静态文件,否则我一直工作。所以,css文件没有加载。
So, I got it all working except my admin page does not load the static files. So, the css file is not loaded.
这是我的settings.py:
This is my settings.py :
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static/')
我也试图使用:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'static').
但仍然无效。
这是我的eb配置文件:
this is my eb config file :
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python papp/manage.py migrate --noinput"
leader_only: true
02_createsuperuser:
command: "source /opt/python/run/venv/bin/activate && python papp/manage.py createsu"
leader_only: true
03_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python papp/manage.py collectstatic --noinput"
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "papp.settings"
PYTHONPATH: "/opt/python/current/app/papp:$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: "papp/papp/wsgi.py"
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"
在进行更改后,我使用了eb deploy命令。
I used eb deploy command after making the changes.
我需要做更多的步骤吗?我已经在这里阅读:默认Django 1.5管理员css不工作我需要改变别名,但它是apache。
Is there extra steps that I need to do ? I have read in here : Default Django 1.5 admin css not working that i need to change alias, but it is for apache.
我还从django doc文件中读取,例如 https://docs.djangoproject.com/en/1.8/howto/static-files/ ,但我不知道在STATIC_ROOT中为AWS提供什么?
I also read from django doc files such as https://docs.djangoproject.com/en/1.8/howto/static-files/ but im not sure of what to put in the STATIC_ROOT for AWS
任何帮助都非常感激。感谢
any help is much appreciated. Thanks
推荐答案
事实证明:aws:elasticbeanstalk:container:python:staticfiles将您的EC2实例上的目录中的文件/ opt / python / current / app / static / )to / static /
It turns out "aws:elasticbeanstalk:container:python:staticfiles" maps files in your directory on your EC2 instance (/opt/python/current/app/static/) to /static/
将settings.py中的STATIC_ROOT设置为os.path.join (BASE_DIR,'..','static')修正问题
setting STATIC_ROOT in settings.py to os.path.join(BASE_DIR, '..','static') fixed the issue
这篇关于Amazon Web Service(AWS)上的Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!