2006年07月30日 星期日 16:29
不得已
还是采用了Manipulator
def thumbnail(content):
size = (48,48)
image = Image.open(content)
image = image.convert('RGB')
image = image.resize(size)
return image
class ImageManipulator(forms.Manipulator):
def __init__(self, request=None):
self.request = request
self.fields = [
forms.ImageUploadField(field_name="icon"),
]
def save(self, group):
file_obj = self.request.FILES.get('icon', None)
if file_obj:
path, ext = os.path.splitext(file_obj['filename'])
if group.icon:
filename = group.get_icon_filename()
if os.path.exists(filename):
try:
os.remove(filename)
except:
pass
group.save_icon_file(self.user.id + ext,
thumbnail(file_obj['content']))
group.save()
可是最终上传总会:No file was submitted. Check the encoding type on the form.
这是个什么原理呢? 我分别用jpg和BMP格式实验了 还是不行 不知道为什么
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060730/40fbc8b3/attachment.html
2006年07月31日 星期一 09:01
2006年07月31日 星期一 13:46
Zeuux © 2025
京ICP备05028076号