Tuesday, October 6, 2015

Load a static file with a variable name

Hi everybody,

I want to load a image with a variable name   in  detail.html like this:

{% load staticfiles %}
<img src="{% static 'pet/images/{{pet.name}}.png' %}" alt={{ pet.name }} />

the image won't load. But when I try this way, it's work perfectly:

{% load staticfiles %}
<img src="{% static 'pet/images/nova.png' %}" alt={{ pet.name }} />

Here is my question How to load a static file with a variable name? Ps: pet.name value is always the image's name for each pet.

best regards

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/83297d6e-98a8-4add-96a2-f742e4b423d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment