Handling HTTP

Handling HTTP - CHAPTER 7 Handling HTTP T he Hypertext...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
163 CHAPTER 7 Handling HTTP T he Hypertext Transfer Protocol (HTTP) is the fundamental language for communication over the Web. It’s spoken by both Web servers and Web browsers, along with a variety of spe- cialty tools for dealing with the Web. The Python community has done a tremendous amount of work to standardize the behavior of applications that interact with HTTP, culminating in PEP- 333, 1 the Web Server Gateway Interface (WSGI). Since Django follows the WSGI specification, many of the details listed in this chapter are a direct result of compliance with PEP- 333. Requests and Responses Because HTTP is a stateless protocol, at its heart is the notion of a request and a response. Clients issue a request to the server, which returns a response containing the information requested by the client or an error indicating why the request couldn’t be fulfilled. While requests and responses follow a detailed specification, Django provides a pair of Python objects that are designed to make the protocol much easier to deal with in your own code. A basic working knowledge of the protocol is useful, but most of the details are handled behind the scenes. These objects are described in this section, along with notes indicating the relevant portions of the specification that should be referenced. HttpRequest As described in Chapter 4, every Django view receives, as its first argument, an object repre- senting the incoming HTTP request. This object is an instance of the DpplNamqaop class, which encapsulates a variety of details concerning the request, as well as some utility methods for performing useful functions. The base DpplNamqaop class lives at `f]jck*dppl , but individual server connectors will define a subclass with additional attributes or overridden methods that are specific to the Web server being utilized. Any overridden methods or attributes should behave as documented here, and any additional information will be best documented in the code for the server inter- face itself. 1. dppl6++lnk`f]jck*_ki+lal)< ///+
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CHAPTER 7 N HANDLING HTTP 164 HttpRequest.method The HTTP specification outlines a variety of verbs that can be used to describe the type of request being performed. This is typically referred to as its method , with different request methods having specific expectations of how they should be handled. In Django, the method being used for the request is represented as the iapdk` attribute of the DpplNamqaop object. It will be included as a standard string, with the method name in all uppercase letters. Each method describes what the server should do with the resource identified by the URL. Most Web applications will only implement GET and POST, but a few others are worth explaining here as well. Further details on these—and others not listed here—can be found in the HTTP specification, 2 as well as many other resources on the Web.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/11/2010 for the course COMP 2405 taught by Professor Imranahmed during the Winter '10 term at Carleton CA.

Page1 / 19

Handling HTTP - CHAPTER 7 Handling HTTP T he Hypertext...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online