Getting MEDIA images on Amazon S3 server on template

此生再无相见时 提交于 2019-12-08 12:55:20

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/17721079/getting-media-images-on-amazon-s3-server-on-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!