密码字段不排除-Django

时间:2018-12-27 10:03:31

标签: django django-forms

我想从表单中删除password1字段。但这并不排除。甚至我也不想删除密码字段,只是想从表单中禁用。

Forms.py

{
    "pubA":"",
    "pubB":"",
    "pubC":"",
    "ipA":{
        "aA":{
            "a":"",
            "b":"",
            "c":""
        },
        "aB":{
            "a":"",
            "b":"",
            "c":""
        },
        "aC":{
            "a":"",
            "b":"",
            "c":""
        }
        ......
    },
    "ipB":{
        "bA":{
            "a":"",
            "b":"",
            "c":""
        },
        "bB":{
            "a":"",
            "b":"",
            "c":""
        },
        "bC":{
            "a":"",
            "b":"",
            "c":""
        }
        ......
    }
}

1 个答案:

答案 0 :(得分:1)

UserRegisterForm

new_user = f.save(commit=True)
new_user.password = new_user.set_password('sdfasd')

forms.py

class UserRegisterForm(ModelForm):
    class Meta:
        model = User
        fields = ('first_name', 'last_name', 'email', )