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

前端 未结 5 1007
[愿得一人]
[愿得一人] 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:22

    Override _clean methods and put your checks in them. You can modify cleaned_data from there.

    E.g:

    def clean_password(self):
        new1 = self.cleaned_data['password']
        return new1
    

    Every fields in the form will have a field_name_clean() method created automatically by Django. This method is called when you do form.is_valid().

提交回复
热议问题