I have URL's of images stored in a List in python.
How should I display those images on my web page using Django.
Asked
Active
Viewed 886 times
-2

arpitjain2402
- 120
- 10
1 Answers
1
Try with:
# HTML file
# If your list is 'urls'
{% for url in urls %}
<img src="{{ url }}" />
{% endfor %}
EDIT
From your comment, I got your Urls list, you should save your list like this:
['toi.cricbuzz.com/scripts/images/toi-logo.gif', 'toi.cricbuzz.com/scripts/images/cb-logo.png', 'img.cricketcb.com/i/gallery/fth/140x75/images/2015/oct/2/…', 'img.cricketcb.com/i/gallery/fth/140x75/images/2015/oct/1/…', 'img.cricketcb.com/i/gallery/fth/140x75/images/2015/sep/27/…', 'img.cricketcb.com/i/gallery/fth/140x75/images/2015/sep/17/…']
You can test this list above in your template, it should display images.

Gocht
- 9,924
- 3
- 42
- 81
-
1it would be endfor not endif – gaurav_kamble Oct 02 '15 at 19:47
-
@gaurav_kamble thanks, I edited. – Gocht Oct 02 '15 at 19:48
-
I tried using this, but I am getting TypeError : unhashable type: 'dict' . – arpitjain2402 Oct 03 '15 at 04:04
-
@arpitjain2402 show your list of urls please. – Gocht Oct 03 '15 at 04:19
-
The list gets changes on every request : PFB the list for one request : ['http://toi.cricbuzz.com/scripts/images/toi-logo.gif', 'http://toi.cricbuzz.com/scripts/images/cb-logo.png', 'http://img.cricketcb.com/i/gallery/fth/140x75/images/2015/oct/2/prv_63c85_1443793619.jpg', 'http://img.cricketcb.com/i/gallery/fth/140x75/images/2015/oct/1/prv_aa02f_1443711267.jpg', 'http://img.cricketcb.com/i/gallery/fth/140x75/images/2015/sep/27/prv_6b851_1443359583.jpg', 'http://img.cricketcb.com/i/gallery/fth/140x75/images/2015/sep/17/prv_3a2e7_1442542041.jpg', ] – arpitjain2402 Oct 03 '15 at 18:22
-
I don't know why the elements are separated with ';' and every url redirects to a web page, not an image. – Gocht Oct 03 '15 at 19:23
-
I agree. I need to display all the image through these image URLs on one single web page . Any suggestions for that . – arpitjain2402 Oct 04 '15 at 17:33
-
@arpitjain2402 I edited the answer – Gocht Oct 04 '15 at 17:39