css在aws上的django的管理页面中不起作用

时间:2015-10-16 14:30:36

标签: python css django amazon-web-services amazon-ec2

我遵循了本教程:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html#python-django-create-app

除管理页面中的css

外,一切正常

我已经尝试过了:

Default Django 1.5 admin css not working

Django on Amazon Web Service (AWS)

但没有成功

我有以下配置:

folia_eb.config:
container_commands:
01_migrate:
command: "django-admin.py migrate"
leader_only: true
02_collectstatic:
command: "django-admin.py collectstatic --noinput"
leader_only: true

option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "folia_eb.settings"
PYTHONPATH: "/opt/python/current/app/folia_eb:$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: "folia_eb/folia_eb/wsgi.py"
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"

settings.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static/')

有人可以帮助我吗?

提前致谢

2 个答案:

答案 0 :(得分:2)

我在管理网站上找到了相同的CSS文件问题:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html#python-django-create-app

对我有用的是:

.ebextensions / django.config:

container_commands:
   01_collectstatic:
      command: "python manage.py collectstatic --noinput"
      leader_only: true

option_settings:

   aws:elasticbeanstalk:container:python:
      WSGIPath: ebdjango/wsgi.py
   aws:elasticbeanstalk:container:python:staticfiles:
      "/static": "static/"

将以下行添加到ebdjango / settings.py:

STATIC_ROOT=os.path.join(BASE_DIR,'static/')

然后eb部署

希望这会有所帮助

答案 1 :(得分:0)

如果您要检查error.log,则会看到类似这样的内容, “〜/ webapp_django / django_project / django_app / static / admin / css / sensitive.css”(无此类目录), 解决的简单方法是将所有管理界面静态文件复制到应用程序静态文件文件夹中。与为Django应用程序设置不同的静态文件夹相比,它要容易得多。

cp -a source destination
cp -a /home/usr/env/lib/python3.X/site-packages/django/contrib/admin/static/admin/ /home/usr/project_dir/application_dir/static/