[Django]-Invalid stdimage image path in admin

0👍

The URL of an ImageField is like this

upload_to='uploaded_images/%Y/%m/%d',

This path is relative to your MEDIA_URL.
Let’s suppose you’re visiting http://site/admin/auth/user.
If in this page you have a link of this type

<a href="uploaded_images/2012/11/28/file.ext">Anchor</a>

The link will point to

http://site/admin/auth/user/uploaded_images/2012/11/28/file.ext

Which is what you get, and is obviously wrong.

Long story short, the answer is that you MUST prepend the path stored with MEDIA_URL
Which may be

MEDIA_URL = '/media/' (the slash at the beginning points to the domain root)

or

MEDIA_URL = 'http://domain/media/' (might be redundant)

Leave a comment