Django 图像上传:IOErrno2 找不到路径——但它仍然在那里保存图像?
我遇到一个问题,本地版本的 Django 正在按预期处理图像上传,但我的服务器却没有。注意:我在 MediaTemple.net(网格服务器)上使用 Django 容器,
这是我的代码。
def view_settings(request):
<snip>
if request.POST:
success_msgs = ()
mForm = MainProfileForm(request.POST, request.FILES, instance = mProfile)
pForm = ChangePasswordForm(request.POST)
eForm = ChangeEmailForm(request.POST)
if mForm.is_valid():
m = mForm.save(commit = False)
if mForm.cleaned_data['avatar']:
m.avatar = upload_photo(request.FILES['avatar'], settings.AVATAR_SAVE_LOCATION)
m.save()
success_msgs += ('profile pictured updated',)
<snip>
def upload_photo(data,saveLocation):
savePath = os.path.join(settings.MEDIA_ROOT, saveLocation, data.name)
destination = open(savePath, 'wb+')
for chunk in data.chunks():
destination.write(chunk)
destination.close()
return os.path.join(saveLocation, data.name)
这就是它变得古怪的地方,我希望有人能够阐明这个错误,因为要么
- 是错误的错误代码,要么
- 是文件在完全处理之前发生了一些事情。
回顾一下,该文件实际上已上传到服务器的预期目录中 - 但此错误消息仍然存在。
/user/settings 处出现 IOError
[Errno 2] 没有这样的文件或目录: u'/home/user66666/domains/example.com/html/media/images/avatars/DSC03852.JPG'
环境:
请求方式:POST 请求网址: http://111.111.111.111:2011/user/settings Django 版本:1.0.2 最终 Python 版本:2.4.4 安装的应用程序: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'ctrlme', '用户工具','easy_thumbnails'] 安装的中间件: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware')
回溯:文件 “/home/user6666/containers/django/leonidas/usertools/views.py” 在视图设置中 51. m.avatar = upload_photo(request.FILES['avatar'], settings.AVATAR_SAVE_LOCATION)文件 “/home/user666666/containers/django/leonidas/usertools/functions.py” 在上传照片中 91. 目的地 = open(savePath, 'wb+')
I have an issue where the local version of Django is handling image upload as expected but my server is not. Note: I am using a Django Container on MediaTemple.net (grid server)
Here is my code.
def view_settings(request):
<snip>
if request.POST:
success_msgs = ()
mForm = MainProfileForm(request.POST, request.FILES, instance = mProfile)
pForm = ChangePasswordForm(request.POST)
eForm = ChangeEmailForm(request.POST)
if mForm.is_valid():
m = mForm.save(commit = False)
if mForm.cleaned_data['avatar']:
m.avatar = upload_photo(request.FILES['avatar'], settings.AVATAR_SAVE_LOCATION)
m.save()
success_msgs += ('profile pictured updated',)
<snip>
def upload_photo(data,saveLocation):
savePath = os.path.join(settings.MEDIA_ROOT, saveLocation, data.name)
destination = open(savePath, 'wb+')
for chunk in data.chunks():
destination.write(chunk)
destination.close()
return os.path.join(saveLocation, data.name)
Here's where it gets whacky and I was hoping someone could shed a light on this error, because either
- it's the wrong error code, or
- something is happening with the file before it's completely handled.
To recap, the file was actually uploaded to the server in the intended directory - and yet this err msg continues to persist.
IOError at /user/settings
[Errno 2] No such file or directory:
u'/home/user66666/domains/example.com/html/media/images/avatars/DSC03852.JPG'Environment:
Request Method: POST Request URL:
http://111.111.111.111:2011/user/settings
Django Version: 1.0.2 final Python
Version: 2.4.4 Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites', 'ctrlme',
'usertools', 'easy_thumbnails']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')Traceback: File
"/home/user6666/containers/django/leonidas/usertools/views.py"
in view_settings
51. m.avatar = upload_photo(request.FILES['avatar'],
settings.AVATAR_SAVE_LOCATION) File
"/home/user666666/containers/django/leonidas/usertools/functions.py"
in upload_photo
91. destination = open(savePath, 'wb+')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论