variable to a template

42 views
Skip to first unread message

luca72

unread,
Mar 2, 2016, 5:41:37 AM3/2/16
to Django users
Hello i have write this in a template:
{% for a in lista %}
            <img src="{% static "mysite/scorr/{{a}}" %}" width="100" height="100" </img> 
 {% endfor %}
But i get no image

if i add just a <p> {{a}} </> i see that the file name is righ, 
also if i direct write the file i get it
 {% for a in lista %}
            <img src="{% static "mysite/scorr/myfile.jpg" %}" width="100" height="100" </img> 
 {% endfor %}

can you tell me what is wrong

Thanks

Sergiy Khohlov

unread,
Mar 2, 2016, 5:52:05 AM3/2/16
to django-users
original path  og your image please.
 Also setting for STATIC_ROOT  from setting.py send please

Many thanks,

Serge


+380 636150445
skype: skhohlov

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9a12167f-e919-4632-b77a-6d5acc80fd3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

luca72

unread,
Mar 2, 2016, 6:00:23 AM3/2/16
to Django users
Hello Thanks for your reply

STATIC_URL = '/static/'

I have no static root configured

But why if i write   <img src="{% static "mysite/scorr/myfile.jpg" %}" width="100" height="100" </img>  i get the image

and if i write  <img src="{% static "mysite/scorr/{{a}}" %}" width="100" height="100" </img> where a is the file name i can't get?

The path is 
F:\Sito_01_03_16\test\nuovo\myproject\mysite\static\mysite\scorr

Thanks for your help  

Sergiy Khohlov

unread,
Mar 2, 2016, 7:57:59 AM3/2/16
to django-users
 try to use :
"{% static "mysite/scorr{{a}}" %}"



Many thanks,

Serge


+380 636150445
skype: skhohlov

Andreas Schosser

unread,
Mar 2, 2016, 8:05:24 AM3/2/16
to django...@googlegroups.com
Hi Luca,

> <img src="{% static "mysite/scorr/{{a}}" %}" width="100"
> height="100" </img>

Try {% static "mysite/scorr/"|add:a %}

Andreas

--
Kurs 10 IT-Consulting www.kurs-10.de
Andreas Schosser a...@kurs-10.de

Baldestraße. 14 Telefon +49 89 41615842-0
80469 München Telefax +49 89 41615842-3

0x6EDECCF1 - 2AA0 939B 5585 819B FCE8 E43B 0B8E 0DF2 6EDE CCF1

luca72

unread,
Mar 2, 2016, 8:12:46 AM3/2/16
to Django users
Thanks now it works

Luca

ra...@hellofrom.amsterdam

unread,
Mar 2, 2016, 12:10:50 PM3/2/16
to Django users
Hi Luca,

Did {{ a }} solve the problem?

Cheers,
Raoul

Fred Stluka

unread,
Mar 2, 2016, 12:28:57 PM3/2/16
to django...@googlegroups.com
Luca,

You can't nest a variable evaluation (via {{}}) inside a tag
execution {%%}.  But you can put them side by side to achieve
the effect you want:

'{% static "mysite/scorr" %}'/{{a}}'

--Fred
Fred Stluka -- mailto:fr...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

Chris Bartos

unread,
Apr 9, 2016, 9:31:11 AM4/9/16
to Django users
There are probably 3 ways you can do this:

You should be able to use the "add" filter to concatenate two strings. 

2) Map the elements of your array in your view with the contents of settings.STATIC_URL. 

3) You can't nest a context variable inside another tag like you're trying to do but you can concatenate two variables together:

{% static 'my_app' %}/{{filename}}

I hope that helps.
Reply all
Reply to author
Forward
0 new messages