Lukas Klein

Python and Django developer. Docker enthusiast. This is my blog.

Changing request.POST values in Django

When you try to change request.POST in a Django view it will raise a QueryDict instance is immutable exception. In order to change/add values you have to create a shallow copy instead of a binding.

def index(request):
    if request.method == 'POST':
        post_mutable = request.post.copy()
        # Now you can change values:
        post_mutable['answer'] = 42