I just want to display the image that I uploaded through the admin module through the html image tag on the web page. Image is in /home/user/work/djcode/media/chicks/blondie.jpg.
Here is the relevant part of my models.py
class Image(models.Model): model_name = models.CharField(max_length=50) model_pic = models.ImageField(upload_to='chicks/') def __unicode__(self): return self.model_name
Here is the relevant part of my views.py
def main(request): i = get_object_or_404(Image, pk=1) return render_to_response('polls/main.html', {'image': i}, context_instance=RequestContext(request))
The html tag I'm using is just
<img src="{{ MEDIA_ROOT }}/{{ image.model_pic.url }}">
From settings.py, my media root is MEDIA_ROOT = '/ home / user / work / djcode / media'
Please note that the {{image.model_pic.url}} variable shows "chicks / blondie.jpg" through the html template, so I think my image object is really well sent to the template.
Can anyone give me a hand with this? That would be very helpful.
Thanks so much for your time!
source share