Though other answers are good but i just wanted to add one thing here;
We have now two ways to update a request.data
object But before that, check if it is a QueryDict (as already mentioned by @mikebridge);
from django.http.request import QueryDict
if isInstance(request.data, QueryDict):
request.data._mutable = True
After that, to update the request.data, first way is;
request.data.update({'key': 'new_value'})
this will work fine, but say if the request.data['key'] which you want to update is a list, then the value will not get changed completely by the new_value
but it will get appended to the older list which may cause trouble and you may not get the desired result.
So to overcome that, i.e, to completely change the value of some key, use the second method;
request.data['key'] = 'new_value'
This will change the value of request.data['key']
completely to new_value
.
request.data['age'] = 30
. now i can't do that as request.data is string not dict. now if usedata = json.loads(request.data)
thenrequest.data = json_data
then i get error not able to set attribute on request