4 ways receiver front-end back-end data is transmitted

1, by way of an incoming query string  

DEF Test (Request): # query string parameter passing mode acquisition 
    A = request.GET.get ( ' A ' )   # A to healthy 
    B = request.GET.getlist ( ' B ' ) # where to build a multi-value (QuerySet that) 
    return A, B

2, url parameter passing mode

DEF test1 (Request, X, Y): # URL parameter passing mode receiving 
    Print (X, Y)
     return X + Y

3, in a transmission mode form_data

DEF test2 (Request): # form-Data parameter passing mode receiver 
    name = request.POST.get ( ' name ' ) 
    password = request.POST.get ( ' password ' )   # listing manner GetList () method 
    return name

 

4, the data transmission to json

Import json 

DEF get_body_json (Request):
     # Get json data types: 
    json_bytes = request.body
     # The bytes type into STR 
    json_str = json_bytes.decode () 

    # python3.6 and higher versions, json.loads () method may receive str type and bytes 
    # However python3.5 and the following version, json.loads () method can only receive str, 
    # 3.5 of the above coding step needed. 

    REQ_DATA = json.loads (json_str)
     Print (REQ_DATA [ ' a ' ] )
     Print (REQ_DATA [ ' B ' ])
     return the HttpResponse ( 'OK')

 

Guess you like

Origin www.cnblogs.com/wjun0/p/11569716.html