is it necessary enough in my boss's django code
this is the code:
params = dict(request.REQUEST.items())
but i think it is not necessary , because i th开发者_高级运维ink the request.REQUEST must be the dict ,
so it should be :
params = request.REQUEST
am i right ?
thanks
The documentation states:
For convenience, a dictionary-like object that searches POST first, then GET. Inspired by PHP's $_REQUEST.
(Emphasis added)
HttpRequest.REQUEST is a dictionary-like item. It is not a dictionary. Your boss might've wanted dictionary operations that weren't on the dictionary-like REQUEST object.
no its not a dict its a subclass, django.http.QueryDict see here.
but you are right. there is a items() method.
If this code necessary or not depends on surrounding code, there is not enough information in question.
But generally this code:
params = dict(request.REQUEST.items())
is not the equivalent of
params = request.REQUEST
most probably he wanted to make a copy of the object, this may be useful if later in the code there is a modification of this new dictionary.
it is hard to say how it is being used late in the code, but if this is just used as a code shortcut (to not use long form all the time) then your equivalent code is fine.
精彩评论