Django-媒体上传[Errno 13]权限被拒绝 [英] Django - Media upload [Errno 13] Permission denied

查看:141
本文介绍了Django-媒体上传[Errno 13]权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在让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/')

现在,如果我在uploads文件夹中创建带日期的目录并对该文件夹进行chmod到755,上传正常,但是如果我尝试对upmods文件夹进行chmod而不创建带日期的子文件夹(我需要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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆