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

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

问题描述

我正在使用 Django 1.5 &Python 3.2.3.

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?

我的表单定义如下:

class UserCreateForm(UserCreationForm):

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

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

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.

推荐答案

您需要从 sctratch 创建表单,它不应扩展 UserCreationForm.UserCreationForm 有一个显式定义的用户名字段以及一些其他字段.您可以在此处查看.

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天全站免登陆