You should just be able to take out the MEDIA_ROOT portion of your upload_to path. So instead of: upload_to='%s/images/' % settings.MEDIA_ROOT You would have: upload_to='images/'
That should make it store the relative address and not the absolute address in your database. As for {{photo.image_file.url}} generating the absolute address instead of the correct url, double-check your "MEDIA_URL" string in your main settings file. It should be set to something like 'http:// www.example.com/media/' or 'http://www.example.com/site-media/', and should definitely be different than you "MEDIA_ROOT" setting. -Michael On Mar 26, 12:36 am, Julien Phalip <jpha...@gmail.com> wrote: > Hi, > > Sorry if my question seems trivial, but I've looked around for an > answer and I'm really at loss... > > I've got a simple model: > > class Photo(models.Model): > image_file = models.ImageField(_('image file'), upload_to='%s/ > images/' % settings.MEDIA_ROOT) > > But when I upload an image via the admin it saves the whole path into > 'image_file' (e.g. '/home/blah/media/images/example.gif'). Shouldn't > it just save the relative path (e.g. 'images/example.gif')? > > The problem is that if in a template I do: > > <img src="{{ photo.imafe_file.url }}"> > > ... it generates the following: > > <img src="/home/blah/media/images/example.gif"> > > I'm using a fresh checkout of Django from today. I tested both on > windows and on a Linux server. > > Thanks a lot, > > Julien --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---