How to Convert URLField in a Image on Django
<p>I have kept the url of an image on a URLField, such that as well as I can display the image on the model of my home page and not the string of the URL, I can not convert that direction, "www.google.es/images/car "in an image of a car?</p>

<p>models.py</p>

<pre><code>Photo class (models.Model):
Â Â Â Â  name = models.CharField (max_length = 150)
Â Â Â Â  url = models.URLField ()
Â Â Â Â  __unicode def __ (self): # 0 parameters
Â Â Â Â Â Â Â Â  return self.name
</code></pre>

<p>views.py</p>

<pre><code>def home (request):
Â Â Â Â  photos = Photo.objects.all ()
Â Â Â Â  html = '&lt;ul&gt;'
Â Â Â Â  for photo in photos:
Â Â Â Â Â Â Â Â  html + = '&lt;li&gt;' + photo.url + '&lt;/ li&gt;'
Â Â Â Â  html + = '&lt;/ ul&gt;'
Â Â Â Â  return HttpResponse (html)
</code></pre>

<p>How could i convert in a imagen <code>photo.url</code> into a Image.</p>

<p>You cannot convert the string into image however you can use the url in <code>src</code> attribute inside <code>&lt;img&gt;</code> tag</p>

<pre><code>for photo in photos:
     html + = '&lt;li&gt;&lt;img src="' + photo.url + '"&gt;&lt;/ li&gt;'
</code></pre>

<p>Remember that you are generating HTML for the website not rendering it's content</p>

python django