0

I need to use a variable for creation of a url for the img html tag. I use python - Django.

Here's a hardcoded example of what I need:

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

And here's what I tried (but failed):

I want to use x.id variable (currently it equals 1), in my url. Something like this:

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

What am I missing?

Klaus D.
  • 13,874
  • 5
  • 41
  • 48
  • 2
    The philosophy of django template is to put logic in the view not in the template. You should create the value `"/images/{x.id}.png"` directly in the view. – luxcem Nov 25 '22 at 13:12
  • The answer you need may be found there : https://stackoverflow.com/questions/16655851/django-1-5-how-to-use-variables-inside-static-tag – Emile Nov 25 '22 at 13:45

0 Answers0