python - django: concatinating strings to create a url to static image in template -
i'm trying load image url composed of vairable numerical value. there template solution or have create filter in extras.py? rather write 1 liner. along following lines:
{% urltemp="media/"|add:info.personid|stringformat:"s"|add:".jpg" %} <img src="{% static urltemp %}" onerror="this.style.display='none'"/> {% endwith %}
i know can use {% static your_url %}
allways prefer this:
i have images in myproject/static/img/
my {{static_url}}
(settings.py variable) points myproject/static
so in template do: <img src="{{static_url}}img/image_name.png" />
or using imagefield
{% item in item_list%} <img src="{{ item.image.url }}" /> {% endfor %}
in case do:
<img src="{{ media_url }}{{ info.personid }}.jpg" />
{{ media_url }}
ends /
- you need
media_url
defined in settings.py
Comments
Post a Comment