Show internet image in my Django app

Asked

Viewed 41 times

0

Hi, I’m learning to use Django. I wonder if you have any way to reference static files that are not saved on my server. Example:

In this way HTML works: <img {% Static 'name_da_imagem_here.jpg' %}>

I wish I could put:

<img url({% Static 'http://s3.amazonaws.com/caymandemo/wp-content/uploads/site/10/2015/09/ 30162427/sep2.jpg' %})">

Or something like that. Since in Django we need to tell which directories are serving static files for them to upload, I don’t know if there’s a way to say 'Hey, Django. Take these links I’m going through and serve as a static file on my page''.

Can you clear me of the doubt if this is possible? And, if so, how should I do?

PS:I have searched the documentation and the internet and could not find anything about it.

  • it is not easier to download the image and place it in your image folder?

  • @Carloscortez, I believe that Julio is wanting to use a CDN. Julio Cesar, you could confirm?

  • So whether or not it’s easier isn’t the point. I’m wondering if there’s any way to do this as a learning experience even if I have to deal with it in the future for some reason, you know? But, really, it’s simpler just to download the image and display itself haha. It’s more a curiosity of my own, understand?

1 answer

0

You do not need to use {%Static '' %} in this case, just pass the url normally, this way:

<img src='http://s3.amazonaws.com/caymandemo/wp-content/uploads/sites/10/2015/09/30162427/sep2.jpg'>

What you need to check is that in Bucket caymandemo the objects are public and if your domain has CORS access permission, this can be configured in Bucket itself.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.