Python论坛  - 讨论区

标题:[python-chinese] [django]图片上传部分

2006年07月30日 星期日 16:29

风向标 vaneoooo at gmail.com
Sun Jul 30 16:29:50 HKT 2006

不得已
  还是采用了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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年07月31日 星期一 09:01

HoLin holin.he at gmail.com
Mon Jul 31 09:01:00 HKT 2006

On 7/30/06, 风向标 <vaneoooo at gmail.com> wrote: > > > 不得已 > 还是采用了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格式实验了 还是不行 不知道为什么 > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -- Regards HoLin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060731/58dafb4e/attachment-0001.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年07月31日 星期一 13:46

风向标 vaneoooo at gmail.com
Mon Jul 31 13:46:12 HKT 2006

   
在06-7-31,HoLin <holin.he at gmail.com> 写道: > > < form *ENCTYPE="multipart/ form-data"* ACTION="upload.php" METHOD="POST"> > > On 7/30/06, 风向标 <vaneoooo at gmail.com> wrote: > > > > 不得已 > 还是采用了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格式实验了 还是不行 不知道为什么 > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > -- > Regards > > HoLin > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060731/97acdbf4/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号