Reputation: 3589
If I use the params for pass a list in GET method:
fetch_physicalserver_list(){
var params = {
id_list: this.physicalserver_id_list // there is [24, 26, 27]
}
this.$Lml_http('get', this.$Api_urls.user_productmanage_physicalserver.list(), params, response => {
this.physicalserver_list = response.data.results
console.log( response.data.results)
}, error => {
})
}
And in the request, the id_list
convert to the id_list[]=24&id_list[]=27&id_list[]=27
.
and I don't know how to get the id_list
in the backend.
I use the method to get the id_list[]
I will only get the first id
, if I get id_list
, I will get nothing.
the code of get_param_from_query_params
method:
def get_param_from_query_params(query_params, param):
param_temp = None
try:
mutable = query_params._mutable
query_params._mutable = True
param_list = query_params.pop(param)
param_temp = param_list[0] if (isinstance(param_list, list) and len(param_list) > 0) else ''
query_params._mutable = mutable
except Exception as e:
pass
return param_temp
So, I have two questions:
1.The params's id_list converted to id_list[]
. where is the official description?
2.How can I get the id_list
after I passed to the backend?
Upvotes: 0
Views: 53
Reputation: 309049
Firstly, you are using the key id_list[]
, so you must use id_list[]
to retrieve the key in Django. Including []
in JavaScript is a convention to show there are multiple values, but it makes no difference to Django.
If you want a list of values instead of a single value, then use pop_item
instead of pop
.
It's not clear to me why you need the get_param_from_query_params
method. You are returning param_list[0]
which means you'll only ever get a single item. It would be much simpler to use getlist
:
id_list = query_params.getlist('id_list')
Upvotes: 3