0

我制作了自己的表单验证器来创建和编辑用户。用户创建工作正常,密码在数据库中正确散列。但是当我尝试使用它登录时,我遇到了识别错误。我已经跟踪了 set_password 中传递的密码,它是正确的......

有什么问题?

谢谢

表格 :

class UserForm(ModelForm):
    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)
        self.fields['groups'].help_text = 'Los grupos a los que este usuario pertenece.'
    class Meta:
        model = User
        fields = {
                    'username',
                    'first_name',
                    'last_name',
                    'email',
                    'is_staff',
                    'is_active',
                    'groups',
                    'password'
                 }
        widgets = {
                   'groups': CheckboxSelectMultiple()
        }
    def save(self, commit=True):
        user = super(UserForm, self).save(commit=False)
        user.set_password(self.cleaned_data["password"])
        if commit:
            user.save()
        return user

风景 :

def usuario_new(request):
    form_errors = None
    if request.method == "POST":

        formset = UserForm(request.POST or None)
        if formset.is_valid():
            formset.save()
            return usuarios(request)
    else:
        formset = UserForm()

    context = {'formset': formset,
               'form_errors': form_errors }
    return render_to_response("administracion/usuarios/new.html",
                              context,
                              context_instance=RequestContext(request))
4

1 回答 1

0

Ok, someone help me.

the fields must use [] and not {} I'm not sure why, but that resolved my problem.

于 2013-06-13T16:13:52.900 回答