Modify value of a Django form field during clean()

It is possible to modify a value of a field during clean() if you update self.data attribute of a Form. self.data is an instance of the QueryDict class. By default, querydicts are immutable. To make them mutable, you should use .copy() method. From the documentation:

The QueryDicts at request.POST and request.GET will be immutable when accessed in a normal request/response cycle. To get a mutable version you need to use QueryDict.copy()

self.data = self.data.copy()
self.data['your_field'] = 'new value'

change self data in the clean method to change the value which gets displayed


Way to update value in clean() is update the value in form's data dictionary:

self.data["a34_stuff"] = "html"

This works for sure.