python - django ajax used to transmit the data array and is converted into a list of background

One. Ajax front end

var order_list that = [. 1, 2,. 3 ]; 

$ .ajax ({ 
    URL: "/ Stores / Order /" , 
    Method: "the POST" , 
    Traditional: to true ,     // plus the parameter (serialized data) 
    Data: {
         'order_list that' : the JSON.stringify (order_list that),
         'csrfmiddlewaretoken': $ ( "[name = 'csrfmiddlewaretoken']" ) .val (), 
    }, 
    Success: function (Data) { 
        the console.log (Data); 
    }, error: function (Data) { 
        Alert ( "request error! ' ) 
    } 
})

 

two. rear end

DEF Order (Request): 
    order_list that = request.POST.getlist ( " order_list that " ) 
    order_list that = analysis_str_list (order_list that)
     # database operations get the array 
    for order_id in order_list that: 
        order_obj = Order.object.filter (ID = order_id). First () 
    
    # ..... 

DEF analysis_str_list (S):    
     "" " custom list of analytical methods " "" 
    this_list = [] 
    Li = S [0] .replace ( " [ " , "" ).replace("]", "").split(",")
    for i in li:
        for j in i:
            try:
                int(j)
                this_list.append(int(j))
            except Exception as e:
                pass
    return this_list 

 

Guess you like

Origin www.cnblogs.com/chaoqi/p/11228418.html