sharkfin
sharkfin

Reputation: 3847

Broken img tag when using url from another site

I was playing with making a custom CheckboxSelectMultiple widget for my form. I added an img tag to the widget with the src pointing to another website that contained the image.

I receive broken images when I display my form. The source page seems correct when I view it:

<li><label for="id_display_0"><input type="checkbox" name="display" value="&lt;data" id="id_display_0" /> <img src="www.fakeplace.com/s.jpg"/></label></li> 

But when I click on the link in the img src, it complains about a 404:

Request URL: http://127.0.0.1:8000/browse/www.fakeplace.com/s.jpg

. I think it has to do with how static media works, but I am unsure how to work around it (I don't want to store the images on my local machine right now).

Upvotes: 0

Views: 2732

Answers (2)

rickyduck
rickyduck

Reputation: 4084

As steve and prashanth said, prefix http://

Also I recommend putting an alt tag, even if it is blank, for accessibility and conformity reasons, eg

<img src="http://www.fakeplace.com/s.jpg" alt=""/>

Upvotes: 0

Steve Mayne
Steve Mayne

Reputation: 22818

Replace:

<img src="www.fakeplace.com/s.jpg"/>

with:

<img src="http://www.fakeplace.com/s.jpg"/>

Otherwise, to the browser it looks like a relative URL.

Upvotes: 4

Related Questions