22👍
✅
You can’t change the request.GET
or request.POST
as they are instances of QueryDict
which are immutable according to the docs:
QueryDict instances are immutable, unless you create a copy() of them. That means you can’t change attributes of request.POST and request.GET directly.
8👍
Your code should work if you add one little step: you are now making a copy of the request.GET
, but you have not assigned it back to the request
. So it is just a standalone object which is not related to the request
in any way.
This would the the necessary improvement:
tempdict = self.request.GET.copy()
tempdict['state'] = ['XYZ',]
tempdict['ajaxtype'] = ['facet',]
self.request.GET = tempdict # this is the added line
print(self.request.GET)
I have tested it in writing custom middleware, but I assume it works the same way in all places.
Source:stackexchange.com