How can I change a Django form field value before saving?

前端 未结 5 1015
[愿得一人]
[愿得一人] 2021-01-31 08:29
if request.method == \'POST\':
    userf = UsersModelForm(request.POST)
    username = userf.data[\'username\']
    password = userf.data[\'password\']
    passwordrepea         


        
5条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 09:21

    See the documentation for the save() method

    if request.method == 'POST':
        userf = UsersModelForm(request.POST)
        new_user = userf.save(commit=False)
    
        username = userf.cleaned_data['username']
        password = userf.cleaned_data['password']
        passwordrepeat = userf.cleaned_data['passwordrepeat']
        email = userf.cleaned_data['email']
    
        new_user.password = new1
        new_user.passwordrepeat = new2
    
        new_user.save()
    

提交回复
热议问题