如何将缩略图存储在与 Django ImageKit 相同的文件夹中?

How to store thumbnails in the same folder with Django ImageKit?

有没有人有过使用ImageKit管理缩略图的经验?

目前我的 models.py 中有以下内容:

class Item(models.Model):
    id = models.AutoField(primary_key=True)
    owner = models.ForeignKey(
        get_user_model(),
        on_delete=models.SET_NULL,
        null=True,
        blank=True
    )
    image = ProcessedImageField(
        upload_to=image_upload,
        blank=True,
        validators=[validate_image],
        format='JPEG',
        help_text="Max file size is 3 MB."
    )
    image_thumbnail = ImageSpecField(
        source='image',
        processors=[ResizeToFill(50, 50)],
        format='JPEG',
        options={'quality': 60}
    )

我想重命名缩略图并将其存储在特定文件夹中(不是 ImageKit 默认的 CACHE/images/ 文件夹),但不能弄清楚如何做到这一点(并在缩略图上添加“upload_to”会给我一个错误)。非常感谢所有帮助!谢谢!

根据 docs:

ImageSpecFields, on the other hand, are virtual—they add no fields to your database and don’t require a database. This is handy for a lot of reasons, but it means that the path to the image file needs to be programmatically constructed based on the source image and the spec.

如果您不想将文件存储在缓存文件夹中,您可能只想坚持使用 ProcessedImageFIeld。