Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

285
Vistas
How can I use the value of a model atributte inside a <img> src?

I am trying to create a project in which a model attribute is used as part of an image name. I have tried many methods and I think I am close to the solution, but I have a problem. This is my code:

<img src="{% static 'media/{{model.atributte}}.jpg' %}"  alt="{% static 'media/{{model.atributte}}.jpg' %}"></img>

For example: if the value of the attribute is "img" this should result in = static/media/img.jpg My intention was to use that to set the src path but this is the result I get in the HTML.

/static/media/%7B%7Bmodel.atributte%7D%7D.jpg

I appreciate any kind of help or recommendation, as an extra comment, I want to clarify that if I write the value of the attribute in the src it does locate the image, but would always do it for the same model and I have several models. Thanks in advance.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

If you let Django serve media files during development, and let the webserver (like Apache, Nginx, etc.) serve the media files during production, you can work with the .url attribute:

<img src="{{ model.atributte.url }}"  alt="{{ model.atributte.url }}">

For more information, see the serving files uploaded by a user during development section of the documentation.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda