I get a message
[Errno 13] Permission denied: u '/ home / ... / ... jpg' when I try to upload a file to django. But the problem only occurs when I try to use it with localhost /. When I run or debug it using localhost: 8000, I don't get any problems.
I create function folders when I run a script to install my database.
My code is:
def handle_uploaded_file(request,f): user=Users.objects.get(id_u=request.user.id) url=settings.MEDIA_URL+'images/'+user.mail+'/gallery/'+f.name fullurl=settings.MEDIA_ROOT+'images/'+user.mail+'/gallery/'+f.name #comprobar si existe el archivo if not os.path.exists(fullurl): destination = open(fullurl, 'wb+') ... destination.close()
Permissions in folders. I want to upload files to the "images" folder. Here I see that others do not have write permissions, but the up folder has 777. So, why does my script change permissions when creating subfolders?
4 drwxrwxrwx 3 bernardo www-data 4096 ago 3 09:42 . 4 drwxrwxr-x 11 bernardo www-data 4096 jul 31 12:36 .. 4 drwxrwxr-x 5 bernardo bernardo 4096 ago 3 09:42 images
My http.config
ServerName localhost WSGIPythonPath /home/bernardo/workspace/mbosoziales Alias /media/ /home/bernardo/workspace/mbosoziales/media/ Alias /static/ /home/bernardo/workspace/mbosoziales/static/ <Directory /home/bernardo/workspace/mbosoziales/static> Order deny,allow Allow from all </Directory> <Directory /home/bernardo/workspace/mbosoziales/media> Order deny,allow Allow from all </Directory> WSGIScriptAlias / /home/bernardo/workspace/mbosoziales/mbosoziales/wsgi.py <Directory /home/bernardo/workspace/mbosoziales/mbosoziales> <Files wsgi.py> Order deny,allow Allow from all </Files> </Directory>
So, I have to change permissions every time after running the first script, which makes folders for users, because they do not have write permissions in the media folder, although I believe that the rights to them are correct.
sudo chgrp -R www-data images/ chmod -R o+w images/
Any help would be greatly appreciated. And sorry for my english :)
Added complete exception: Environment:
Request Method: POST Request URL: localhost:8000/user/upload/ Django Version: 1.4 Python Version: 2.7.3 Installed Applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'admin', 'login', 'suchen', 'user', 'photologue') Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware') Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view 20. return view_func(request, *args, **kwargs) File "/home/bernardo/workspace/mbosoziales/user/views.py" in upload 332. handle_uploaded_file(request,request.FILES['file']) File "/home/bernardo/workspace/mbosoziales/user/views.py" in handle_uploaded_file 344. destination = open(fullurl, 'wb+') Exception Type: IOError at /user/upload/ Exception Value: [Errno 13] Permission denied: u'/home/bernardo/workspace /mbosoziales /media/images/ bern@ardo.com /gallery/list.csv'