简体   繁体   English

Django AWS S3 媒体文件

[英]Django AWS S3 media files

Working with Django, I am trying to use AWS S3 storage only for uploading and reading files which is working well at MEDIA_URL but the problem when using AWS S3 is that somehow I am losing reference to STATIC_URL where CSS and javascript files are使用 Django,我尝试仅将 AWS S3 存储用于上传和读取在 MEDIA_URL 上运行良好的文件,但使用 AWS S3 时的问题是我不知何故失去了对 STATIC_URL 的引用,其中 CSS 和 javascript 文件是

I only want MEDIA_URL pointing to S3 and keep my STATIC_URL away from AWS S3... Is that possible?我只希望 MEDIA_URL 指向 S3 并使我的 STATIC_URL 远离 AWS S3 ...这可能吗?

# Static asset configuration                                         
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

if DEBUG:
   MEDIA_ROOT = os.environ['MEDIA_ROOT']
   MEDIA_URL = os.environ['MEDIA_URL']
else: 
   DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
   AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
   AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
   AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
   MEDIA_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME

Change STATIC_URL to "STATIC_ROOT = os.path.join(BASE_DIR,'static')".将 STATIC_URL 更改为“STATIC_ROOT = os.path.join(BASE_DIR,'static')”。 Could use decouple to hide those variables too.也可以使用 decouple 来隐藏这些变量。

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

相关问题 Django Admin S3 私有媒体文件 - Django Admin S3 Private Media Files 我无法让 AWS S3 在我的 Django/Heroku 应用程序上提供媒体文件 - I can't get AWS S3 to serve media files on my Django/Heroku App 在 Flutter 中从 AWS S3 上传和获取媒体文件 - Upload & fetch media files from AWS S3 in Flutter Django + AWS s3 可以上传文件但不能访问它们 - Django + AWS s3 can upload files but not access them Django AWS S3 object 存储boto3媒体上传错误 - Django AWS S3 object storage boto3 media upload error 使用 AWS media convert 自动转换所有现有的 s3.mp4 文件 - Auto convert all existing s3 .mp4 files using AWS media convert Django 在 AWS S3 中托管 static 个文件,在尝试访问管理字体文件时导致 CORS 错误 - Django hosting static files in AWS S3 causing CORS error when trying to access admin font files 在连接到 AWS S3 Bucket 上传提供商的 Strapi 媒体库上上传文件时出现“文件为空”错误 - 'FIles are Empty' error when uploading files on Strapi Media Library which connects to AWS S3 Bucket upload provider 上传到 S3 之前的 AWS 临时文件? - AWS temporary files before uploading to S3? aws转码器覆盖s3上的文件 - aws transcoder overwrite files on s3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM