使用Ajax和Django传递数组的Dict

时间:2017-09-07 16:54:01

标签: python arrays ajax django

我有一个dictionary of arrays我希望传递给我的Django视图。

       $.ajax({
            url: '/fund_monitor/fund_directory',
            type: 'GET',
            data:{
                filter_dict: filter_dict,
            },
            success: function (data) {
                console.log(filter_dict);
            }
        });

在我看来,我希望收到这个词:

    if request.is_ajax():
        filter_dict = request.GET.getlist('filter_dict')
        print("Is Ajax", filter_dict)

"Is Ajax []"打印出来,仅作为示例,我的filter_dict

Designated Broker:["BMO"]
Fund Class:["OM"]

为什么要传递空白数组?

1 个答案:

答案 0 :(得分:1)

$.ajax({
            url: '/fund_monitor/fund_directory',
            type: 'GET',
            data:JSON.stringify({
                filter_dict: filter_dict,
            }),
            success: function (data) {
                console.log(filter_dict);
            }
        });


if request.is_ajax():
    request_data = json.loads(request.GET)

    filter_dict = request_data['filter_dict']
    print("Is Ajax", filter_dict)