Model for avatars

class UserReg(models.Model): user=models.OneToOneField(User) avatar=models.ImageField(blank=True, upload_to='users/') 

The form

 class UserProfil(forms.ModelForm): avatar = forms.ImageField() class Meta: model = UserReg fields = ('avatar', ) 

"MultiValueDictKeyError at / auth / registration /" crashes, respectively, if I check request.FILES ['avatar'] then the value is None

Why not send images / files ??? I understood there should be 2 main points: 1. The form should be sent using the POST method = "post" 2.

In the form selected field ImageField that I forgot?

  • one
    Most likely the form should be Multipart / form-data . Show the template and view - FeroxTL
  • You are right, forgot about enctype = "multipart / form-data" - user208820

0