简体   繁体   English

django 存储破坏了管理静态文件

[英]django storages breaks the admin staticfiles

I tried moving from local static files to S3 using django-storages.我尝试使用 django-storages 从本地 static 文件移动到 S3。 I followed the documentation carefully but still there is no access to the static files.我仔细阅读了文档,但仍然无法访问 static 文件。

In the local environment I have:在本地环境中,我有:

STATIC_URL = '/static/'

in the settings.py and everything works fine.settings.py ,一切正常。

when I add all the S3 params as the documentation shows:当我按照文档显示添加所有 S3 参数时:

STATIC_URL = 'https://django-main.s3.amazonaws.com/'
ADMIN_MEDIA_PREFIX = 'https://django-main.s3.amazonaws.com/admin/' # tried with this and also without this



DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'


AWS_ACCESS_KEY_ID = '<AWS_ACCESS_KEY_ID>'
AWS_SECRET_ACCESS_KEY = '<AWS_SECRET_ACCESS_KEY>'
AWS_STORAGE_BUCKET_NAME = 'bucket-name'

I ran python manage.py collectstatic which seemed to work fine and uploaded the static files to the bucket.我运行python manage.py collectstatic似乎工作正常并将 static 文件上传到存储桶。

but running the server and going to the admin page it looks like this:但是运行服务器并进入管理页面,它看起来像这样:

在此处输入图像描述

which is because it doesn't have access to the static files.这是因为它无权访问 static 文件。 No error is thrown/shown没有错误被抛出/显示

Any ideas?有任何想法吗?

EDIT:编辑:

So apperently I'm getting a forbbiden call:所以显然我接到了一个禁止电话: 在此处输入图像描述

but I changed my settings.py to:但我将我的 settings.py 更改为:

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')

and made sure that access is available (put a breakpoint and downloaded a css file using boto3 from that bucket using these exact environment variables and still no solution并确保访问可用(放置一个断点并使用这些确切的环境变量从该存储桶中使用 boto3 下载 css 文件,但仍然没有解决方案

The issue was that the bucket read permissions were not public.问题是存储桶读取权限不是公开的。 Changing the permissions worked更改权限有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM