Question

The static files (css, js, images) are serving from local whilst media files (uploaded images and videos) are on Amazon S3 server in my project.

I can upload media files to Amazon S3 without any problem. But I cannot get the URL's of the files on templates.

I have tried the static files and it worked: (But static files will be on the local)

 {% load static from staticfiles %}
 {% static "imagename.png" %}

And how can I do it for MEDIA files?

 {% media "imagename.png" %} # maybe something like that? :)

My settings file is like that:

  INSTALLED_APPS: 'storages'

  DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
  DEFAULT_S3_PATH = "media"

  MEDIA_ROOT = '/%s/' % DEFAULT_S3_PATH
  UPLOAD_DIR = MEDIA_ROOT

  MEDIA_URL = '//s3.amazonaws.com/%s/media/' % AWS_STORAGE_BUCKET_NAME
Was it helpful?

Solution

Just putting {{ imagefield.url }} was enough.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top