Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!