Working with GET, POST, and QueryDict objects
Data can come through an HTTP request as parameters on a URL or inside the body of a POST request. You might have noticed parameters in a URL when browsing the web – the text after ? – for example, http://www.example.com/?parameter1=value1¶meter2=value2. We also saw earlier in this chapter an example of form data in a POST request to log in a user (the request body was username=user&password=password1).
Django automatically parses these parameter strings into QueryDict objects. The data is then available on the HttpRequest object that is passed to your view – specifically, in the HttpRequest.GET and HttpRequest.POST attributes for URL parameters and body parameters respectively. QueryDict objects mostly behave like dictionaries, except that they can contain multiple values for a key.
To show different methods of accessing items in, we’ll use a simple QueryDict (the qd variable) with only one...