Setting MEDIA_URL for Django Heroku App, Amazon S3 -


I installed a MEDIA_URL to your Heroku app, which is currently serving static files through STATIC_URL from Amazon S3 in Is trying for Static files are working fine, but when I try to add a MEDIA_URL in addition to the current STATIC_URL, pages are now presented at all and the app remains to work

The current settings are:.

  Avs_storej_bket_nam = 'Buketnme' Statikfiles_storej = 'Storgeskbackendsks3botoks3BotoStorage' S3_uarel = 'http: //%sks3kamzonoskcom/'% Avs_storej_bket_nam Sthatik_uarel = S3_uarel Avs_akses_ke_id = 'Key' AWS_SECRET_ACCESS_KEY = 'SECRET_KEY'   

when I add:

  MEDIA_URL = S3_URL DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'   

This problem is caused especially, MEDIA_URL is problematic when DEFAULT_FILE_STORAGE has been deleted, it is still the same problem. But I am trying to ensure that how the media uploaded by the user is unsuccessful.

If anyone has any information about how to achieve it, it would be most appreciated.

STATIC_URL and MEDIA_URL can not have the same value, it generates an error

I still have this problem and I can not find a clear way to do it. Wait for better answer, but in this way I solved it (ugly hack):

I am using and Since media files appear in the root of my S3 bucket, I can access them through STATIC_URL. In my settings.py:

  COMPRESS_URL = "https://s3.amazonaws.com/bucketname/" STATIC_URL = COMPRESS_URL   

in your local dev The environment I use at MEDIA_URL and STATIC_URL for production Set an environment variable that is correct for your local env and false on Heroku and put it in context_processor env.

Then you can use the media files in your templates like this:

  background-image: url ({% if env == 'true'%} {{MEDIA_URL}} {% Else%} {{STATIC_URL}} {% endif%} {{course.image}});   

It works, but it's ugly. Hopefully someone got a better solution so I ran my code refactor :)

Edit is not a better way:. Allows you to create a stable and a media folder in S3

Comments