Giovanni Bitliner
Giovanni Bitliner

Reputation: 2072

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

I'm creating a django 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?

Upvotes: 1

Views: 2088

Answers (2)

Mudassar Hashmi
Mudassar Hashmi

Reputation: 2899

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

Upvotes: 0

patrickmdnet
patrickmdnet

Reputation: 3392

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.)

Upvotes: 1

Related Questions