24👍
✅
If the data is coming from a request (which is the case if you are using a view) the form.data
dictionary will be a QueryDict
which is supposed to be immutable. Thankfully you can hack your way into changing it by copying it first:
self.data = self.data.copy()
self.data['phone_number'] = 1234567890
If you are changing directly a form instance that is not from a view’s request, you can change the form.data
dictionary (it’s a simple dictionary object this way) directly like so:
# Don't need to copy `data` first
self.data['phone_numer'] = 123456789
Source:stackexchange.com