自定义Django中usercreationform的显示方式 [英] customize the way usercreationform looks in django

查看:90
本文介绍了自定义Django中usercreationform的显示方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Django自定义UserCreationForm。我执行以下操作

I want to customize the UserCreationForm from django. I do the following

class myUserCreationForm(UserCreationForm):


    class Meta:
        model=User
        fields = ('username', 'password1', 'password2')
        widgets = {
            'username':TextInput(attrs={'class':'form-control'}),
            'password':TextInput(attrs={'class':'form-control'}),
            'password2':TextInput(attrs={'class':'form-control'}),
}

,但无法正常工作。呈现模板后,它会在输入框上未附加表单控件类。

but its not working. When the template is rendered It creates the input boxes don't have the form-control class attached to them. What could be wrong?

推荐答案

您需要通过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中usercreationform的显示方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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