Permission Denied error with Django while uploading a file

前端 未结 4 2011
不思量自难忘°
不思量自难忘° 2020-12-23 17:01

I currently have a simple model defined, with a photoupload feature using django thumbnails plugin.

but when i try to upload it gives me the following error:

<
相关标签:
4条回答
  • 2020-12-23 17:46

    Try checking the permissions on each directory in the path starting at /. Just a thought.

    0 讨论(0)
  • 2020-12-23 17:54

    I just ran into this same problem. And found the solution if you are hosting with Apache as your server. For instance if my settings were:

    MEDIA_ROOT = '/var/www/media/geekingreen'

    then I would simply need to give that folder the correct permissions recursively to make sure that any sub-folders also have the same permission. The default group for apache is www-data so to give permission to my django app I would run these commands.

    cd /var/www/media
    chgrp -R www-data geekingreen/
    chmod -R g+w geekingreen/
    

    The chgrp -R www-data geekingreen/ command changes the directory geekingreen and any subdirectories to have the group www-data.
    The chmod -R g+w geekingreen/ command changes what permissions the group has on all of these folders that now belong to www-data, to now have the write permission. Obviously required for uploads.

    Hope this can help anyone that may have had a similar problem.

    0 讨论(0)
  • 2020-12-23 17:57

    Just in case you run into this when running your development server. I ran the development server as root like this: sudo python manage.py runserver 0.0.0.0:80 in order to test the site with an iPad in the same LAN network. The cache files generated in that session belonged to root. So when I ran the project the next day NOT as root I got the permission denied error.

    0 讨论(0)
  • 2020-12-23 17:59
    mkdir(name, mode)
    
    Exception Type: OSError at /admin/products/photo/add/
    

    but your application is deployed at

    /var/www/django_projects/gangr/../gangr/
    

    Do you have a directory path set to an absolute path "/admin/products/photo/add/" rather than something relative like "admin/products/photo/add/"?

    Check the MEDIA_ROOT and MEDIA_URL in your settings.py file.

    http://docs.djangoproject.com/en/dev/ref/settings/#media-root

    0 讨论(0)
提交回复
热议问题