Django rest-framework Framework - resolver

Parser: 

Start: django: request.POST/ request.body 
    satisfy two requirements at the POST have value 
    1. If the request Content-Type header: application / x-www-form -urlencodeed, request.POST only in It has the value (the analysis data request.body) 
    2. data format requirements: 
        name-Alex $ $ Gender Age = X = 18 is 
    such as: 
     . A form submission form 
         <form> 
         	.... 
         	.... 
         </ form> 
      B . ajax Submit 
          # request.POST no value, request.body has the value 
          $ .ajax {( 
          	URL: ..., 
          	type: the POST, 
          	headers: { 'the type-the Content': 'file application / JSON'}, 
          	Data: {name : X, =} Age, 10 
          )} 

rest_framework parser:

Import JSONParser rest_framework.parsers from, FormParser 

# json format allows users to send the data-type Content: file application / json 
# { "name": "Alex", "Age": 10} 
class the TestView (APIView): 
      #JSONParser represented only parse content-type; application / json head 
      #FormParser represents only parse content-type; application / x- www-form-urlencoded header 
      parser_classes = [JSONParser, FormParser,] 
      DEF POST (Self, Request, * args, ** kwargs) : 
      	  return request.data 

global: 
"DEFAULT_PARSER_CLASSES": [ "rest_framework.parsers.JSONParser", "rest_framework.parsers.FormParser"] 
   
parser uses to cook the global configuration on it

  

Guess you like

Origin www.cnblogs.com/kuku0223/p/11346399.html