Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django request QueryDict Errors on pop()

Looking at dir(request.GET), I notice that pop is listed as a method. I also believe i've popped off attributes from request in the past.

Is that accurate? If so, why would this fail?

request.GET.pop('key')
like image 366
Ben Avatar asked Oct 27 '11 22:10

Ben


1 Answers

request.GET and request.POST are immutable QueryDict instances. This means you cannot change their attributes directly.

Copying a QueryDict, returns a mutable QueryDict. You can then call the pop method of the copy without raising an error.

request.GET
GET = request.GET.copy()
GET.pop('key')    
like image 85
Alasdair Avatar answered Sep 27 '22 17:09

Alasdair