Django的在亚马逊Web服务(AWS) [英] Django on Amazon Web Service (AWS)

查看:732
本文介绍了Django的在亚马逊Web服务(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它似乎是亚马逊的文档是有点过时了(他们仍然使用而不是Django的管理员django-admin.py),以及它的某些部分不工作(当东西不工作中,我回退到realpython链接之一)。

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/')

我也曾尝试使用:

i have also tried to use :

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'static'). 

但它仍然无法正常工作。

but it still does not work.

这是我的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进行更改后部署命令。

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://开头的文档。 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

任何帮助是非常AP preciated。谢谢

any help is much appreciated. Thanks

推荐答案

原来AWS:elasticbeanstalk:容器:蟒蛇:staticfiles地图文件目录上的EC2实例(的/ opt /蟒蛇/电流/ APP /静态/ )以/静态/

It turns out "aws:elasticbeanstalk:container:python:staticfiles" maps files in your directory on your EC2 instance (/opt/python/current/app/static/) to /static/

设置STATIC_ROOT在settings.py到os.path.join(BASE_DIR,'..','静')固定的问题

setting STATIC_ROOT in settings.py to os.path.join(BASE_DIR, '..','static') fixed the issue

这篇关于Django的在亚马逊Web服务(AWS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆