change a form value before validation in Django form

前端 未结 4 1400
难免孤独
难免孤独 2021-02-19 03:00

I have a django form and on my view function I do this :

search_packages_form = SearchPackagesForm( data = request.POST )

I would like to overw

4条回答
  •  再見小時候
    2021-02-19 03:21

    form.is_valid() runs through your form's (and model's in case of a ModelForm) clean method's, returning True or False

    If you plan on changing form data you can do it within the general clean method or at field level, e.g.

    class YourForm(DerivingClass):
        # regular stuff
    
        def clean_(self):
            # here
            return self.cleaned_data
    
        def clean(self):
            # or here
            return super(YourForm, self).clean()
    

提交回复
热议问题