Error updating form with Imagefield

Asked

Viewed 59 times

0

When registering a new record with upload saved normally, but updating shows the following error: inserir a descrição da imagem aqui

Meu formulário

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

I gave a print on var picture and when registering a new image shows.png, but when updating it becomes directory/image.png.

  • 2

    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.

  • See if it helps https://coderwall.com/p/bz0sng/simple-django-image-uploadto-model-imagefield

1 answer

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.