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.
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.