pythondjangodjango-formsdjango-allauthdjango-1.8

Adding a FileField to a custom SignupForm with django-allauth


I have the following custom SignupForm (simplified, works perfectly without my_file):

class SignupForm(forms.Form):
    home_phone = forms.CharField(validators=[phone_regex], max_length=15)
    my_file = forms.FileField()

    def signup(self, request, user):
        new_user = ReqInfo(
            user=user,
            home_phone=self.cleaned_data['home_phone'],
            my_file=my_file,
        )
        new_user.save()

In models.py:

class ReqInfo(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True)
    home_phone = models.CharField(
        validators=[phone_regex], max_length=15)
    my_file = models.FileField(upload_to='uploads/directory/', validators=[resume_file_validator], blank=True, null=True)

My issue:

When I add a a user in myurl/accounts/signup it tells me that the my_file field is Required, even though I select a file.


Solution

  • The signup.html template allauth uses did not have

    enctype="multipart/form-data"
    

    After adding it, it works like a charm.