Adding a FileField to a custom SignupForm with django-allauth

被刻印的时光 ゝ 提交于 2020-01-06 19:55:27

问题


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.


回答1:


The signup.html template allauth uses did not have

enctype="multipart/form-data"

After adding it, it works like a charm.



来源:https://stackoverflow.com/questions/34376019/adding-a-filefield-to-a-custom-signupform-with-django-allauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!