Django, uploading file: [Errno 13] Permission denied: '/media/name.txt'
I'm creating a 开发者_如何学Pythondjango upload file module following this django documentation: UploadFiles
Bun when it executes
destination = open('/media/name.txt','wb+')
it throws this error
[Errno 13] Permission denied: '/media/name.txt'
But my settings are:
- a media folder, called 'media', that is in root of the django project
- this folder 'media' have 777 as permissions (checked through ls -l), and the owner of it is the same that executes the django app (checked through lsof -i)
- settings-py of the project have '/home/pippo/...PROJECT_FOLDER/media' as MEDIA_ROOT and 'http://127.0.0.1:8000/media/' as MEDIA_URL
Due these settings, it seems very strange that this error is throwed.
Some help?
You say media is at the root of the django project, but it appears django is trying to open a folder media at the root of your filesystem. Try
open('media/name.txt','wb+')
or
open('/home/pippo/...PROJECT_FOLDER/media/name.txt,'wb+')
(replace ... with the appropriate intermediate directories.)
You must had created a folder with root user ownership or with any other user. Otherwise you won't be getting this error. Check each folder and if you find root as owner then do "sudo chown -R theusernamme:theusername /folder/folder
精彩评论