request Django view function in response to the request and response objects

  

The official document:

https://docs.djangoproject.com/en/1.11/ref/request-response/

 

View request request object:

When the page is requested, Django creates a HttpRequest object that contains metadata about the request.

Common values ​​and operations:

·          Request.method      # request for obtaining property

·          Request.GET         # get GET parameters dictionary information requested by .get () value

·          Request.POST        # obtain POST parameter dictionary information requested by .get () value

·          Request.body        # obtain the original user-submitted data bytes type

·          Request.path_info   # acquisition request a file path

·          Request.get_full_path () # get the full path to the requested file (containing the query parameters)

·          Request.path   # acquisition request a file path

·          Request.META                        # acquisition request data header information

 

Note: a plurality of key-value pair is the time , such as checkbox type of input labels, SELECT labels, with: request.POST.getlist ( "Hobby")

 

In the view response in response to:

When Django loads the appropriate view, HttpRequest first argument passed to the view function. Each view is responsible for returning an HttpResponse object.

There are three main forms of response object:

O     the HttpResponse ()     response string

O     the render ()               response template file

O     the redirect ()             response 30 X- codes redirect

 

Status code: 301 and 302

 

1 ) 301 and 302 similarities and differences.

In common: 

301 and 302 status codes indicate redirection, that browser in getting this status code returned by the server will automatically jump to a new URL address, the address from the response of Location acquisition (see the header of the user the effect that he typed in the address a moment into another address B ) - this is a common denominator.

 

the difference:

301 represents the old address A resource has been permanently removed (this resource can not be visited), search engines crawl at the same time new content will also exchange the old URL to URL after redirection;

 

302 represents the old address A resource is still (still access), this is only a temporary redirect from the old address A jump to the address B , the search engine will crawl new content and save the old URL. SEO302 better than 301

 

 

2 ) Redirect reasons:

( 1 ) Site adjustment (such as changing the page directory structure);

( 2 ) is moved to a new address page;

( 3 ) change the page extension ( such as application need to .php into .Html or .shtml) .

      In this case, if not redirect, the user favorites, or search engine database in the old address will only make customers get access to a 404 page error message traffic loss in vain; Also some registered multiple domain site also we need to redirect users to access these domain names automatically jump to the primary site and so on.

 

Guess you like

Origin www.cnblogs.com/open-yang/p/11221466.html