Django 1.5:UserCreationForm&自定义认证模型 [英] Django 1.5: UserCreationForm & Custom Auth Model

查看:115
本文介绍了Django 1.5:UserCreationForm&自定义认证模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django 1.5& Python 3.2.3。



我有一个自定义的Auth设置,它使用电子邮件地址而不是用户名。在模型中定义了无用户名。工作正常然而,当我建立用户创建表单时,它会添加一个用户名字段。所以我试着定义要显示哪些字段,但它仍然迫使用户名字段进入表单...甚至甚至在自定义认证模型中也不存在。我如何让它停止这样做?



我的表单定义如下:

  class UserCreateForm(UserCreationForm):

class Meta:
model = MyUsr
fields =('email','fname','surname' 'password1','password2',
'activation_code','is_active')

文档,自定义用户和内置表单表示必须重新编写任何自定义用户模型。我认为这是我在这里做的。这一点,也不是 UserCreationForm文件都说什么更多关于这一点。所以我不知道我错过了什么。我没有通过Google找到任何东西。

解决方案

您需要从sctratch创建表单,不应该扩展UserCreationForm 。 UserCreationForm具有明确定义的用户名字段以及一些其他字段。您可以查看此处


I'm using Django 1.5 & Python 3.2.3.

I've got a custom Auth setup, which uses an email address instead of a username. There's no username defined in the model at all. That works fine. Yet, when I build a user creation form, it adds in a username field anyway. So I tried defining exactly which fields I want displayed, but it's still forcing a username field into the form anyway.... even tho it doesn't even exist in the custom auth model. How can I make it stop doing that?

My form for this is defined like so:

class UserCreateForm(UserCreationForm):

    class Meta:
        model = MyUsr
        fields = ('email','fname','surname','password1','password2',
                  'activation_code','is_active')

At the docs, the Custom Users and Builtin Forms says it "Must be re-written for any custom user model." and I think that's what I'm doing here. Neither this, nor the UserCreationForm documentation say anything more about this though. So I don't know what I'm missing. I didn't find anything via Google either.

解决方案

You need to create your form from sctratch, it should not extend the UserCreationForm. The UserCreationForm have a username field explicitly defined in it as well as some other fields. You can look at it here.

这篇关于Django 1.5:UserCreationForm&自定义认证模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆