[Fixed]-Django – Media upload [Errno 13] Permission denied

24👍

The process that is running your Python interpreter doesn’t have permission to write into the media directory. You’ll need to either chgrp or chown the media directory to the same group as your Python process, and ensure you have at least g+rwx on directories and g+rw on files.

27👍

I was getting the same error and fix it by changing:

MEDIA_ROOT = '/media/'

to:

MEDIA_ROOT = 'media/'

Under settings.py.

2👍

Make sure you have done following

Your settings.py

...
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
...

Also set permission to media directory

chgrp -R www-data /path/to/media/
chmod -R g+w  /path/to/media/
👤bikram

1👍

For me, I forgot to add: MEDIA_ROOT = os.path.join(BASE_DIR,’media’) to my settings.py file on my production server.

0👍

Thanks to https://stackoverflow.com/users/10949995/clement-tong for the inspiration. I experienced the same error in a production environment and I had to change settings.py file to include a preceding forward slash:

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

0👍

I was getting the same error and fix it by doing the following in setting.py file of the project:

MEDIA_ROOT = '/media/'

to

MEDIA_ROOT = 'media/'

Leave a comment