Skip to content Skip to sidebar Skip to footer

Why Copy Post Data In Django Instead Of Working With It Directly?

Django code samples involving post data often shows code similar to this: if request.method == 'POST': post = request.POST.copy() #do stuff with post data Is there a reason

Solution 1:

I think it is because request.POST itself is defined immutable. If you want a version you can actually change (mutability), you need a copy of the data to work with.

See this link (request.POST is a QueryDict instance).


class QueryDict

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.

Post a Comment for "Why Copy Post Data In Django Instead Of Working With It Directly?"