Tuesday, October 6, 2015

Re: Load a static file with a variable name

The '+' is an error, the line look more like this:

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

On Tue, Oct 6, 2015 at 2:33 PM, I. Dié <idie.levano@gmail.com> wrote:
I tried in your way to concatenate, I don't get any exception, but  the image image does'nt want to display. The plage only throw the "alt" value. Even for this line of code it's thing.


Le mardi 6 octobre 2015 19:51:04 UTC+2, Shawn Milochik a écrit :
Try this:

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

You're embedding {{pet_name}} in a string. If this was a regular Python statement, it would be like writing "Hello, {0}" and not having a format() at the end.

--
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/f29da80b-ffe4-421c-9aba-8ad76b87a484%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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/CAOhTVJEUZO_EQAoKSb-iSAEMumgc0StGctVYP55RxJoDXUYxww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment