Django:上载ICO fi时出现键错误

2024-04-19 03:47:52 发布

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

我的模型是:

class Logo(models.Model):
    TYPES=(('logo', _('Logo')),('fav', _('Favicon')))

    type = models.CharField(max_length=10, choices=TYPES, default='logo')

    mimeType = models.CharField(
        max_length=127,
        verbose_name=_('Mime Type'),
        blank=True,
        null=True
    )

    src = ProcessedImageField(
        upload_to='logos/',
        options={'quality': 60},
        verbose_name=_('Source')
    )

    faviconLength = models.IntegerField(verbose_name=_('Favicon length'), blank=True, null=True)
    favicon = models.TextField(verbose_name=_('Favicon'), blank=True, null=True)

    group = models.ForeignKey(
    Group,
    related_name='logo_group',
    verbose_name=_('Group'),
    null=False,
    blank=False
    )

    def __unicode__(self):
        return self.src.name

    class Meta:
        verbose_name = _('Logo')
        verbose_name_plural = verbose_name

当我尝试上载ICO文件时,出现以下异常:

在/admin/tenant/logo/add处出现键错误/ '图标'

我的问题是:ICO文件有什么问题?你知道吗


Tags: namesrctrueverbosemodelsnulllengthmax
1条回答
网友
1楼 · 发布于 2024-04-19 03:47:52

我想我找到答案了。在PIL文档中,我看到ICO是只读的,但我尝试执行写操作。这就是问题所在。经过2个小时的调试和google:D我很抱歉,问题出在编码上。当我将字段更改为FileField时,就没有问题了。你知道吗

相关问题 更多 >