Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suspicious Operation Django

Tags:

python

django

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

like image 611
tsoporan Avatar asked Dec 23 '09 00:12

tsoporan


1 Answers

I got this error when I put a leading slash in the upload_to definition.

BAD

pic = models.ImageField(upload_to="/uploads/product_images/") 

GOOD

pic = models.ImageField(upload_to="uploads/product_images/") 
like image 171
PhoebeB Avatar answered Oct 13 '22 17:10

PhoebeB