Django - 媒体上传 [Errno 13] 权限被拒绝 [英] Django - Media upload [Errno 13] Permission denied
问题描述
我在让 django 很好地处理图片上传时遇到了一些麻烦.我的脚本将根据日期创建目录,如下所示:
I'm having some trouble getting django to play nice with image uploads. My script will create directories based on the date like so:
file = models.FileField(upload_to='uploads/%m-%Y/')
现在,如果我在上传文件夹中创建日期目录并将文件夹更改为 755,则上传工作正常,但如果我尝试在不创建日期子文件夹的情况下更改上传文件夹(我需要 django 来做),我收到权限错误.
Now, if I create the dated directory in the uploads folder and chmod the folder to 755, the upload works fine, but if I try to chmod the uploads folder without creating the dated sub folder (which I need django to do), I am getting a permissions error.
如何使文件夹允许创建子文件夹?
How do I make it so a folder will allow the creation of sub folders?
这是一个回溯:
Django Version: 1.3
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.admin',
'tagging',
'mediamanager',
'livesettings',
'projects']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Traceback:
File "/var/lib/python-support/python2.5/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/var/lib/python-support/python2.5/django/utils/decorators.py" in _wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/var/lib/python-support/python2.5/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/var/www/enigma-dev/enigma/mediamanager/views.py" in upload_media
24. m.upload_media(data=form.cleaned_data, params=params)
File "/var/www/enigma-dev/enigma/mediamanager/models.py" in upload_media
63. self.save()
File "/var/lib/python-support/python2.5/django/db/models/base.py" in save
460. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/var/lib/python-support/python2.5/django/db/models/base.py" in save_base
543. for f in meta.local_fields if not isinstance(f, AutoField)]
File "/var/lib/python-support/python2.5/django/db/models/fields/files.py" in pre_save
255. file.save(file.name, file, save=False)
File "/var/lib/python-support/python2.5/django/db/models/fields/files.py" in save
92. self.name = self.storage.save(name, content)
File "/var/lib/python-support/python2.5/django/core/files/storage.py" in save
49. name = self._save(name, content)
File "/var/lib/python-support/python2.5/django/core/files/storage.py" in _save
166. os.makedirs(directory)
File "/usr/lib/python2.5/os.py" in makedirs
171. mkdir(name, mode)
Exception Type: OSError at /media-manager/upload/
Exception Value: [Errno 13] Permission denied: '/var/www/site-dev/site/static/uploads/04-2011'
推荐答案
运行 Python 解释器的进程没有写入媒体目录的权限.您需要将媒体目录 chgrp
或 chown
放到与 Python 进程相同的组中,并确保至少有 g+rwx
目录和 g+rw
文件.
The process that is running your Python interpreter doesn't have permission to write into the media directory. You'll need to either chgrp
or chown
the media directory to the same group as your Python process, and ensure you have at least g+rwx
on directories and g+rw
on files.
这篇关于Django - 媒体上传 [Errno 13] 权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!