I am trying to display a image in the django template
html file
{% for imge in q_i %}
<img src="{{ MEDIA_URL }}/{{ imge.0 }}" width="80" height="80" />
{% endfor %}
view.py
#...#
Q_I = []
for q in s_q:
img = Images.objects.get(id=1)
img_path=img.imgfile
Q_I.append(img_path)
return render_to_response('1.html',{'q_i':Q_I},context_instance=RequestContext(request))
But this code is not working. Am i doing it wrong? Thanks in advance
{{q_i}}
– Joran Beasley Jul 8 '13 at 17:10{{q_i}}
? ... you have no{%endfor%}
in your html ... maybe thats the problem? is there any source if you view source? It doesnt work is not a helpful problem description.. you will need to do some more debugging – Joran Beasley Jul 8 '13 at 17:13view.py
code? You are not doing anything useful there. Also, if nothing gets printed for{{q_i}}
, yours_q
isNone
or0
– karthikr Jul 8 '13 at 17:19imgfile = Images.objects.get(id=1).imgfile; Q_I=[imgfile]*len(s_q)
and in the template,<img src="{{ MEDIA_URL }}{{ imge }}" width="80" height="80" />
in the forloop – karthikr Jul 8 '13 at 17:20