[Answered ]-Django admin shows full path to uploaded file, and link contains full path. How can I fix this?

2👍

✅

Use / instead of MEDIA_ROOT. From the docs, upload_to should be:

A local filesystem path that will be
appended to your MEDIA_ROOT setting to
determine the value of the url
attribute.

In other words, the path that you specify in upload_to will be appended to MEDIA_ROOT to form the upload directory, and appended to MEDIA_URL to form the URL to the file.

p.s. it might be worth specifying a subdirectory instead of / just so the uploaded files cannot overwrite your media files. For example, upload_to='uploads/'. To organise you uploads by year/month, you can even do upload_to='uploads/%Y/%m/'. See docs for more details.

👤Shawn Chin

Leave a comment