Getting MEDIA images on Amazon S3 server on template
Asked Answered
D

1

0

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
Discontented answered 18/7, 2013 at 10:33 Comment(0)
D
7

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

Discontented answered 18/7, 2013 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.