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>Try:</p>

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

<p>Perhaps even better, again relying on formatting instead of string concatenation:</p>

<pre><code>def home (request):
     photos = Photo.objects.all ()
     html = '&lt;ul&gt;{}&lt;/ul&gt;'
     html_photos = []
     for photo in photos:
         html_photos.append('&lt;li&gt;&lt;img src="{}"&gt;&lt;li&gt;'.format(photo.url))
     html = html.format("\n".join(html_photos))
     return HttpResponse (html)
</code></pre>

python django