Tuesday, May 21, 2013

problem with ImageField does not show me the picture on a template

Hi all,

I cant show the picture that I upload from the admin site.


settings.py:

MEDIA_ROOT = '/var/www/fourweb/'



models.py:

class picture(models.Model):
    producto_id = models.ForeignKey(producto)
    description = models.CharField(max_length= 250)
    imagen = models.ImageField(upload_to='photos/%Y/%m/%d', help_text = '100px,150px')
    def __unicode__(self):
        return self.description



view.py:

def detail(request, item_id):
    p = get_object_or_404(producto, pk=item_id)
    pictures = picture.objects.filter(producto_id = item_id)
    return render_to_response('detail.html', {'item': p, 'photos': pictures })

and in the tamplate(details.html):


   {% if photos %}
                {% for photo in photos %}
                        <img src="{{ photo.imagen.url }}" height="200" width="200" >
                {% endfor %}
   {% else %}
                <p>No hay imagen para el articulo</p>
   {% endif %}

the last html output code is:

<img src="photos/2013/05/14/picture_67090.jpg" height="200" width="200" >

the problem is that the picture doen't show, the path is broken. What I doing wrong ???.

please your help.

Regards,
Ronny 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment