geekchic
geekchic

Reputation: 2431

Errno 13 Permission denied Django Upload File

I've looked at all the other solutions but nothing seems to work for me. I have this in my settings.

MEDIA_ROOT = '/Desktop/myapp/media/'
MEDIA_URL = 'http://127.0.0.1:8000/media/'

This in my admin.py

    image = models.FileField(upload_to='images/')

I am running this on the localhost server at the moment. When I try to upload an image in admin and save it, I get the error:

[Errno 13] Permission denied: '/Desktop'

I've tried changing the mode using chmod and chown, but I still get the same error. I have even checked lsof -i and Python does seem to have access to this folder. What am I doing wrong?

Upvotes: 3

Views: 11172

Answers (2)

André Fratelli
André Fratelli

Reputation: 6068

I just had the same problem with the absolute path, but I realised something else. I was joining the path like this:

os.path.join(BASE_DIR, "/media")

But, as stated by the documentation:

If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component.

So removing the root slash solves the problem:

os.path.join(BASE_DIR, "media")

Cheers.

Upvotes: 10

geekchic
geekchic

Reputation: 2431

Well I seem to have answered my own question. It was a very minor issue as it turns out. All I did was change the media root to the complete path and voila.

MEDIA_ROOT = 'Users/username/Desktop/myapp/media/'

Upvotes: 7

Related Questions