Skip navigation

I was trying to access POST data in Django the wrong way. I was trying to get data this way:

 
from django.http import HttpResponse   

def myView(request):  	
  return HttpRequest("Post data is: %s" % request["POST"])  

But that resulted in this error because the request object is not a dictionary:

“‘WSGIRequest’ object is unsubscriptable”

The correct way to do this is via request.POST instead of request[“POST”]

  
from django.http import HttpResponse   

def myView(request):
  	return HttpRequest("Post data is: %s" % request.POST)

Too much JavaScript on the brain! In JavaScript the two syntaxes are interchangeable for all objects.

Posted via email from Apphacker’s learning curve

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: