简体   繁体   中英

Pass python list into json

I have a list in python (Django) that I'd like to pass as a json response. But when I console log the data out I get an empty array called num.

numbers = [10,15,20]
def get_data(request, *args,**kwargs):
data = {
    'num': numbers,
    
    
}
return JsonResponse(data)

In flask I would use jsonify:

from flask import jsonify
def get_data(request, *args,**kwargs):
    data = {
        'num': numbers,
    }
return jsonify(data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM