0
def clean_image(self):
picture = self.cleaned_data.get("image")
try:
if picture:
w, h = get_image_dimensions(picture)
if not picture.content_type in "image/png, image/jpg, image/jpeg":
raise forms.ValidationError('Permitido apenas os formatos: *.jpg, *.jpeg, *.png.')
if w > 200 or h > 200:
raise forms.ValidationError('Imagem muito grande, o tamanho tem que ser ' + str(200) + 'px * ' + str(200) + 'px.')
except AttributeError:
"""
Handles case when we are updating the user profile
and do not supply a new avatar
"""
pass
return picture
I managed to solve it that way.
Do not use images to describe code or error messages. This hinders the search for duplicates and makes it impossible for users of screen readers to read.
– Pablo Almeida
See if it helps https://coderwall.com/p/bz0sng/simple-django-image-uploadto-model-imagefield
– Regis Santos