“ascii”编解码器无法解码位置11中的字节0xff:序号不在范围内(128)

2024-05-16 03:59:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用django imagekit创建我的图像字段的缩略图。在

class CustomUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(_('email address'), max_length=254, unique=True)
    image = ProcessedImageField(upload_to= generate_random_filename,
                                processors=[ResizeToFill(640, 640)],
                                format='JPEG',
                                options={'quality': 60})
    avatar = ImageSpecField(source='image',
                            processors=[ResizeToFill(96, 96)],
                            format='JPEG',
                            options={'quality': 60})

现在,我使用django rest framework为上述模型创建了一个序列化程序:

^{pr2}$

我创造了一个泛型.createAPI视图要保存新用户,但会出现错误:

UnicodeDecodeError at /register/
'ascii' codec can't decode byte 0xff in position 11: ordinal not in range(128)

Unicode error hint

The string that could not be encoded/decoded was: "����\u

我不明白。请帮忙。如果我从序列化程序中删除avatar就可以了。在


Tags: djangoinimage程序format序列化emailnot