gpt4 book ai didi

python - django-图像裁剪不起作用

转载 作者:行者123 更新时间:2023-12-01 05:11:08 25 4
gpt4 key购买 nike

尝试使用 django-image-cropping 。我没有收到任何错误,我只是在 Django Admin 中看到了类似 CharField 的内容,而不是 django-image-cropping 功能:

enter image description here

base.py(设置):

from easy_thumbnails.conf import Settings as thumbnail_settings
THUMBNAIL_PROCESSORS = (
'image_cropping.thumbnail_processors.crop_corners',
) + thumbnail_settings.THUMBNAIL_PROCESSORS

easy_thumbnailsimage_cropping 添加到 INSTALLED_APPS

模型.py:

from image_cropping import ImageRatioField
# ...
class Organization(models.Model):
image_cover = models.ImageField(upload_to='media', blank=True, help_text="blah")
cropping = ImageRatioField('image_cover', '308x850')

admin.py:

from django.contrib import admin
from image_cropping import ImageCroppingMixin

class OrganizationAdmin(ImageCroppingMixin, admin.ModelAdmin):
pass

class OrganizationAdmin(admin.ModelAdmin):
filter_horizontal=['categorys']
#...

admin.site.register(Organization, OrganizationAdmin)

最佳答案

您在 admin.py 中定义了两次 OrganizationAdmin。一次,正确地,子类化 ImageCroppingMixin 一次,一次没有。由于后一个定义会覆盖前一个定义,因此您最终会失去 Mixin。它应该是这样的:

from django.contrib import admin
from image_cropping import ImageCroppingMixin

class OrganizationAdmin(ImageCroppingMixin, admin.ModelAdmin):
filter_horizontal=['categorys']
#...

admin.site.register(Organization, OrganizationAdmin)

关于python - django-图像裁剪不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24212237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com