I’ve been running into a problem while trying to delete uploaded images.
The error is along these lines:
SuspiciousOperation: Attempted access to '/media/artists/12-stones/154339.jpg' denied.
After reading around it looks like the error is due to the fact that it’s looking for the image in the wrong place (notice first slash, /media/ doesn’t exist on the filesystem)
My MEDIA_ROOT and MEDIA_URL are:
MEDIA_ROOT = '/home/tsoporan/site/media/'
MEDIA_URL = "/media/
My models upload_to parameter is passed this function:
def get_artist_path(instance, filename):
return os.path.join('artists', slugify(instance.name), filename)
My questions are:
1) How can I fix this problem for future uploads?
2) Is it possible to fix my current images’ paths without having to reupload?
Regards,
Titus
Well, a little grepping around in the code shows that there may be a deeper error message that got homogenized along the way.
in django/core/files/storage.py, line 210 (this is in 1.1.1) we have:
So the error has to be coming out of safe_join().
In django/utils/_os.py, we have the following. Note the ValueError it throws on the third to last line:
===========================
==================
Hmmm, “The joined path is located outside of the base path component”. Now there are a couple of calls to abspathu() in there (which is defined just above this routine and is different for NT than for other OSes). abspathu() converts all non-absolute paths to absolute by tacking on os.cwdu(), the current working directory.
Question: By any chance do you have a symlink (symbolic link) to your media directory? In other words, it’s not a direct child of the project directory? I don’t know if this is a valid question, it just popped out of my head.
Question: What are the values of
self.locationandnamethat are being passed to safe_join()?Wild-ass-guess: is
self.locationempty?Another wild-ass-guess: did MEDIA_ROOT somehow get changed to
/media/?If you have your own copy of Django installed (it’s not hard to do), trying putting some print statements in these routines and then run it as the development server. The print output will go to the console.
Update: Hmmm. You said “2) The values for self.location and name are: /home/tsoporan/site/media and /media/albums/anthem-for-the-underdog/30103635.jpg”
Does the following path make any sense?
Note the …/media/media/… in there.
Also, what OS is this? Django rev?