Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'WSGIRequest' object is not subscriptable

I'm getting this error in this function in my views.py file. It's confusing because I don't know what 'WSGIRequest' is or why it's giving me problems. I know I have a variable called "newUser" because when I take out that one line the print(request.POST) line prints it out.

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?

like image 237
user728222 Avatar asked May 07 '11 17:05

user728222


1 Answers

It means that WSGIRequest does not implement __getitem__. You are trying to treat the HttpRequest object like a dictionary but it's not. If you want to access this newUser variable use the POST object, which implements a dictionary-like interface:

request.POST['newUser']

You'd do well to peruse the Django docs in situations like this.

like image 129
zeekay Avatar answered Nov 16 '22 01:11

zeekay