Why copy data to Django instead of working directly with it?

Django code examples that include post data often show code like this:

if request.method == "POST": post = request.POST.copy() #do stuff with post data 

Is there a reason for copying message data instead of working directly with it?

+5
python django
Feb 26 '10 at 6:26
source share
1 answer

I think this is because request.POST itself is defined unchanged. If you want a version that you can really change (volatility), you need a copy of the data to work.

See this link (request.POST is an instance of QueryDict).




class QueryDict

QueryDict instances are immutable unless you create copy() from them. This means that you cannot directly modify the request.POST and request.GET attributes.

+10
Feb 26 '10 at 6:57
source share



All Articles