38๐
โ
You should make request.POST(instance of QueryDict
) mutable by calling copy
on it and then change values:
post = request.POST.copy() # to make it mutable
post['field'] = value
# or set several values from dict
post.update({'postvar': 'some_value', 'var': 'value'})
# or set list
post.setlist('list_var', ['some_value', 'other_value']))
# and update original POST in the end
request.POST = post
QueryDict
docs โ Request and response objects
๐คndpu
6๐
You could also try using request.query_params
.
-
First, set the
_mutable
property of thequery_params
toTrue
. -
Change all the parameters you want.
request.query_params._mutable = True request.query_params['foo'] = 'foo'
The advantage here is you can avoid the overhead of using request.POST.copy()
.
๐คGovind S Menokee
- [Django]-How to get the name of current app within a template?
- [Django]-Django TextField and CharField is stripping spaces and blank lines
- [Django]-Django-allauth social account connect to existing account on login
0๐
You can do the following (as suggested by Antony Hatchkins)
If using DRF
request.data._mutable = True
request.data['key'] = value
In Django
request.POST._mutable = True
request.POST['key'] = value
๐คDragonFire
- [Django]-Django โ How to use decorator in class-based view methods?
- [Django]-TypeError: data.forEach is not a function
- [Django]-Django storages: Import Error โ no module named storages
Source:stackexchange.com