开发者

Django, uploading file: [Errno 13] Permission denied: '/media/name.txt'

开发者 https://www.devze.com 2023-03-24 14:30 出处:网络
I\'m creating a 开发者_如何学Pythondjango upload file module following this django documentation: UploadFiles

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:

  1. a media folder, called 'media', that is in root of the django project
  2. 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)
  3. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消