On Wed, May 22, 2013 at 2:10 AM, Ronny Villarroel Mendoza
<[email protected]> wrote:
> 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')
The 'upload_to' here refers to a path relative to settings.MEDIA_ROOT,
where django will store files uploaded to this field.
> …
> {% if photos %}
> {% for photo in photos %}
> <img src="{{ photo.imagen.url }}" height="200"
The url here generates a url based upon the path relative to
settings.MEDIA_ROOT, and prepends it with settings.MEDIA_URL. You have
no value for settings.MEDIA_URL, and so the URL generated is
incorrect...
> …
> <img src="photos/2013/05/14/picture_67090.jpg" height="200" width="200" >
as we see here.
>
> the problem is that the picture doen't show, the path is broken. What I
> doing wrong ???.
As well as the things I mentioned above, Django does not serve your
media files for you, it expects that you have made additional
arrangements to serve the directory settings.MEDIA_ROOT at the url
settings.MEDIA_URL.
So:
1) Arrange for your webserver to serve static files from settings.MEDIA_ROOT
2) Set settings.MEDIA_URL to the url that you configured in step 1.
Job done.
Cheers
Tom
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.