WSGIRequest is not decryptable

I get this error in this function in the views.py file. This is confusing because I don’t know what WSGIRequest is or why it gives me problems. I know that I have a variable called "newUser" because when I take this line out, print (request.POST) prints it.

def AddNewUser (request):

a=AMI() if(request.method == "POST"): print(request.POST) print(request["newUser"]) csrfContext = RequestContext(request) return render_to_response("ac/AddNewUser.html", csrfContext) 

`

Why am I getting this error?

+6
source share
1 answer

This means that WSGIRequest does not implement __getitem__ . You are trying to treat an HttpRequest object as a dictionary, but it is not. If you want to access this newUser variable, use a POST object that implements a dictionary-like interface:

 request.POST['newUser'] 

You should be familiar with the Django docs in such situations.

+10
source

Source: https://habr.com/ru/post/887526/


All Articles