How to set-up a Django project with django-storages and Amazon S3, but with different folders for static files and media files?

后端 未结 5 1457
情歌与酒
情歌与酒 2020-11-28 00:47

I\'m configuring a Django project that were using the server filesystem for storing the apps static files (STATIC_ROOT) and user uploaded files (MEDIA_ROO

5条回答
  •  情深已故
    2020-11-28 01:08

    I think the following should work, and be simpler than Mandx's method, although it's very similar:

    Create a s3utils.py file:

    from storages.backends.s3boto import S3BotoStorage
    
    StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static')
    MediaRootS3BotoStorage  = lambda: S3BotoStorage(location='media')
    

    Then in your settings.py:

    DEFAULT_FILE_STORAGE = 'myproject.s3utils.MediaRootS3BotoStorage'
    STATICFILES_STORAGE = 'myproject.s3utils.StaticRootS3BotoStorage'
    

    A different but related example (that I've actually tested) can be seen in the two example_ files here.

提交回复
热议问题