本文介绍了a ImageField能否受图像尺寸限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以设置为Wagtail ImageField
只接受某些尺寸的图像吗?
Can I set make a Wagtail ImageField
only accept images of of certain dimensions ?
推荐答案
不知道是否可行,但是您可以执行以下操作来限制上传大尺寸图片:
Don't know if it's possible, but you can do something like this to restrict uploading images of large sizes:
from wagtail.wagtailadmin.forms import WagtailAdminPageForm
class BlogPageForm(WagtailAdminPageForm):
def clean(self):
cleaned_data = super().clean()
if (cleaned_data.get('image') and somehow_check_if_img_to_large():
self.add_error('image', 'Error! image is to large!')
return cleaned_data
class BlogPage(Page):
image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
description = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel('photos'),
FieldPanel('description')
]
base_form_class = BlogPageForm
这篇关于a ImageField能否受图像尺寸限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!