开发者

Creating a ModelForm for a Modified User Auth django

I have the following code:

class UserForm(ModelForm):
    email = forms.EmailField(widget = forms.TextInput(attrs ={ 'id':'email'}), required=True)
    first_name = forms.CharFiel开发者_如何转开发d(widget = forms.TextInput(attrs = {'id':'fname'}), required=True)
    last_name = forms.CharField(widget = forms.TextInput(attrs = {'id':'lname'}), required=True)
    linked_id = forms.CharField(widget = forms.HiddenInput(attrs = {'id':'linkedid'}))
    password1 = forms.CharField(label=_('Password'), widget=forms.PasswordInput)
    password2 = forms.CharField(label=_('Re-Enter your password'), widget = forms.PasswordInput)

    class Meta:

        model = UserProfile

        fields = ('email', 'first_name', ... (other fields here))

    def clean_password2(self):
        password1 = self.cleaned_data.get("password1", "")
        password2 = self.cleaned_data['password2']
        if password1 != password2:
            raise forms.ValidationError(_("The passwords you entered did not match!"))
        return password2

Basically, I'm trying to create a modified user registration form. And the form actually shows up, which is good. But If a user tries to actually register. Not all the information gets stored in my database. Only the first name and the email get saved...

EDIT::::::

sorry guys, I got it working for the most part, the fields part wasn't set up correctly. But i'm running into one other issue. When I'm viewing a test user on my site, it's not encrypting the password, its just showing the password. How do I get it to encrypt like how it should?


I would suggest you reread the docs here. If you have the problem with understanding how it works you will have to look at the source.

Here is how you create a password field with a label.

password1 = forms.CharField(widget=forms.PasswordInput(attrs={'class':'input_text'}), label='Password')   

Goodluck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜