使用django-allauth将FileField添加到自定义SignupForm [英] Adding a FileField to a custom SignupForm with django-allauth
本文介绍了使用django-allauth将FileField添加到自定义SignupForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有以下自定义SignupForm(简化后,无需my_file即可完美运行):
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()
在models.py中:
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)
我的问题:
当我加一个用户在myurl / accounts / signup中,即使我选择了一个文件,它也告诉我my_file字段是必填字段。
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.
推荐答案
allauth使用的signup.html模板没有
The signup.html template allauth uses did not have
enctype="multipart/form-data"
添加后,它就像一个饰物。
After adding it, it works like a charm.
这篇关于使用django-allauth将FileField添加到自定义SignupForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文