Django form: what is the best way to modify posted data before validating?

前端 未结 2 1013
天涯浪人
天涯浪人 2021-02-19 18:05
form = ContactForm(request.POST)

# how to change form fields\' values here?

if form.is_valid():
    message = form.cleaned_data[\'message\']

Is there

2条回答
  •  我寻月下人不归
    2021-02-19 18:27

    You could also try using request.query_params.

    1. First, set the _mutable property of the query_params to True.
    2. Change all the parameters you want.

      request.query_params._mutable = True
      request.quer_params['foo'] = 'foo'
      

    The advantage here is you can avoid the overhead of using request.POST.copy().

提交回复
热议问题