Simple form not validating

橙三吉。 提交于 2019-12-04 15:38:17

your 'user_registered' signal is sent after the User is saved. So it already has an 'email' field defined.

UPDATE


Using restless thinking :

form = CustomRegistrationForm(request.POST, request.FILES, notvalidateemail=True)

and in form :

def __init__(self, *args, **kwargs):
    self.notvalidateemail = kwargs.pop('notvalidateemail',False)
    super(CustomRegistrationForm, self).__init__(*args, **kwargs)

def clean_email(self):
    if self.notvalidateemail:
        return
    else:
        #your cleaning here
        return email

Problem:

Your form is first saved by django-registration. Then you save it again in user_created.

Solutions:

  1. Use a different form in user_created. One that won't have already saved fields (these from User model like email). You just want to save additional data in user_created, right?

  2. Add some parameters to the form like:

in user_created:

form = CustomRegistrationForm(dontvalidateemail=True, request.POST, request.FILES)

and in form's init;

self.dontvalidateemail = dontvalidateemail

then just check it in clean_email.

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