1

I have a model where users upload pictures to an s3 bucket.

class Curso(models.Model):
    titulo = models.TextField()
    foto = models.ImageField(upload_to='media/cursos') #this goes to mybucket/media/cursos
    alt = models.TextField()
    ...

It uploads fine to the s3 bucket but the source to the images gets stored in the database like

"media/cursos/theimage.jpg"

And I would like to display the images from the objects in a template like this

 <img class='curso__tarjeta--imagen' loading="lazy" src="{{curso.foto}}" alt={{curso.alt}}">

But it doesn't work because the path is not the whole path my s3 bucket

My static tag is pointing to my s3 bucket. My question is: is there a way to do something like this ->

{% load static %}
<img class='curso__tarjeta--imagen' loading="lazy" src="{%static%}{{curso.foto}}" alt={{curso.alt}}">

I'm trying like that but it doesn't work! What should I do? Help! And thank you in advance

pauzca
  • 164
  • 1
  • 12

1 Answers1

1

Thanks to another stackoverflow answer I finally got it

<img class='curso__tarjeta--imagen' loading="lazy" src={{curso.foto.url}} alt="{{curso.alt}}">

And added this to settings.py

AWS_QUERYSTRING_AUTH = False
pauzca
  • 164
  • 1
  • 12