[Django]-Errno – 13 Permission denied: '/media/ – Django

5πŸ‘

βœ…

I got the same error and debugged it using the shell

In your settings.py file:
Change:

MEDIA_ROOT = BASE_DIR / '/media/'
# here, MEDIA_ROOT = '/media/'

To:

MEDIA_ROOT = BASE_DIR / 'media/'
# here, MEDIA_ROOT = 'path-to-project/media/'

I think this happens because you are trying to join your project level dir to the /media/ directory that exists in linux for mounting media. And would cause permission denied because root has the write permissions, you probably aren’t running everything with sudo. So, instead you can remove the first \ to make the directory relative.

3πŸ‘

mkdir --mode=777 -pv /home/rahul/.local/share/virtualenvs/music-69qL54Ia/{admin/main/artist/1/change,media/artists}

chmod -R 777 /home/rahul/.local/share/virtualenvs/music-69qL54Ia

1πŸ‘

Maybe you forgot to add the MEDIA_ROOT to your urls.py.
For more info checkout the docs

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Note: This is not suitable for production use. if thats the case you can checkout the docs

Leave a comment