媒體文件夾中,我得到一個消息errno的13權限被拒絕:與本地主機
[錯誤13]許可被拒絕:U '/家庭/ .../... JPG' 當我嘗試上傳在Django文件。但是,只有當我用localhost /來嘗試它時纔會出現問題。當我用localhost:8000運行或調試時,我沒有問題。
當我運行一個腳本來設置我的數據庫時,我使用一個函數製作文件夾。
我的代碼:
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()
權限在文件夾中的媒體。我想將文件上傳到'圖像'文件夾。在這裏,我看到其他人沒有寫權限,但up文件夾有777.那麼,爲什麼我的腳本在創建子文件夾時會更改權限?
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
我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>
所以,我每次都要更改權限運行的第一個腳本,使文件夾的用戶後,因爲他們沒有權限在寫媒體文件夾,雖然我認爲權限是正確的。
sudo chgrp -R www-data images/
chmod -R o+w images/
任何幫助,將不勝感激。很遺憾,我的英語:)
加滿例外: 環境:
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/[email protected]/gallery/list.csv'
不回答你的問題,但是看看os.path.join(http://docs.python.org/library/os.path.html#os.path.join) – Willian 2012-08-03 10:00:22
+你能添加完整的異常? – Willian 2012-08-03 10:01:19