Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django中的DataTables Ajax错误_Python_Ajax_Django - Fatal编程技术网

Python django中的DataTables Ajax错误

Python django中的DataTables Ajax错误,python,ajax,django,Python,Ajax,Django,我正在django中进行服务器端ajax加载 这是我的代码片段: @login_required def cmdb_list_page_server_side(request): #do not prepare data in view (as in above view), data will be retrieved using ajax call (see get_countries_list below). return render_to_response('cmdb/lis

我正在django中进行服务器端ajax加载

这是我的代码片段:

@login_required
def cmdb_list_page_server_side(request):
#do not prepare data in view (as in  above view), data will be retrieved using ajax call (see get_countries_list below).
    return render_to_response('cmdb/list.html', locals(), context_instance = RequestContext(request))

def get_cmdb_list(request):
    #prepare the params

    #initial querySet
    querySet = CMDB.objects.all()
    #columnIndexNameMap is required for correct sorting behavior
    columnIndexNameMap = {
        0:'envcode',
        1:'appname',
        2:'sysip',
        3   :'ostype',
        4   :'hostname',
        5   :'cpu',
        6   :'mem',
        7   :'rootdisk',
        8   :'storagetype',
        9   :'location',
        10  :'enclosure',
        11  :'position1',
        12  :'position2',
        13  :'unit',
        14  :'serviceIP',
        15  :'manufacture',
        16  :'seller',
        17  :'machinemodel',
        18  :'machinecode',
        19  :'serialnumber',
        20  :'appearance',
        21  :'archtype',
        22  :'partition',
        23  :'storagesize',
        24  :'applevel',
        25  :'domains',
        26  :'netnote',
        27  :'gateway',
        28  :'mask',
        29  :'serviceport',
        30  :'ha',
        31  :'hbIP1',
        32  :'hbIP2',
        33  :'hardwarecharge',
        34  :'systemcharge',
        35  :'appcharge',
        36  :'managegateway',
        37  :'managemask',
        38  :'repairlevel',
        39  :'repairdate',
        40  :'dbinfo',
        41  :'middlewareinfo',
        42  :'nonsysusers',
        43  :'note',
    }
    #path to template used to generate json (optional)
    jsonTemplatePath = 'cmdb/json_cmdb.txt'

    #call to generic function from utils
    return get_datatables_records(request, querySet, columnIndexNameMap,jsonTemplatePath)
文件“'cmdb/json\u cmdb.txt”如下所示:

{
    sEcho: {{sEcho}},
    iTotalRecords: {{iTotalRecords}},
    iTotalDisplayRecords: {{iTotalDisplayRecords}},
    aaData:[
        {% for item in querySet %}
        [
            "{{ item.envcode }}",
            "{{ item.appname }}",
            "{{ item.sysip }}",
            "{{ item.ostype }}",
            "{{ item.hostname }}",
            "{{ item.cpu }}",
            "{{ item.mem }}",
            "{{ item.rootdisk }}",
            "{{ item.storagetype }}",
            "{{ item.location }}",
            "{{ item.enclosure }}",
            "{{ item.position1 }}",
            "{{ item.position2 }}",
            "{{ item.unit }}",
            "{{ item.serviceIP }}",
            "{{ item.manufacture }}",
            "{{ item.seller }}",
            "{{ item.machinemodel }}",
            "{{ item.machinecode }}",
            "{{ item.serialnumber }}",
            "{{ item.appearance }}",
            "{{ item.archtype }}",
            "{{ item.partition }}",
            "{{ item.storagesize }}",
            "{{ item.applevel }}",
            "{{ item.domains }}",
            "{{ item.netnote }}",
            "{{ item.gateway }}",
            "{{ item.mask }}",
            "{{ item.serviceport }}",
            "{{ item.ha }}",
            "{{ item.hbIP1 }}",
            "{{ item.hbIP2 }}",
            "{{ item.hardwarecharge }}",
            "{{ item.systemcharge }}",
            "{{ item.appcharge }}",
            "{{ item.managegateway }}",
            "{{ item.managemask }}",
            "{{ item.repairlevel }}",
            "{{ item.repairdate }}",
            "{{ item.note }}",
            "{{ item.dbinfo }}",
            "{{ item.middlewareinfo }}",
            "{{ item.nonsysusers }}",
        ]
            {% if not forloop.last %}
                ,
            {% endif %}
        {% endfor %}
    ]
}
最后,我从webbrowser(Chrome)获得错误警报窗口,显示datatables格式化错误。 使用firebug,我得到如下错误消息:

{
    sEcho: {{sEcho}},
    iTotalRecords: {{iTotalRecords}},
    iTotalDisplayRecords: {{iTotalDisplayRecords}},
    aaData:[
        {% for item in querySet %}
        [
            "{{ item.envcode }}",
            "{{ item.appname }}",
            "{{ item.sysip }}",
            "{{ item.ostype }}",
            "{{ item.hostname }}",
            "{{ item.cpu }}",
            "{{ item.mem }}",
            "{{ item.rootdisk }}",
            "{{ item.storagetype }}",
            "{{ item.location }}",
            "{{ item.enclosure }}",
            "{{ item.position1 }}",
            "{{ item.position2 }}",
            "{{ item.unit }}",
            "{{ item.serviceIP }}",
            "{{ item.manufacture }}",
            "{{ item.seller }}",
            "{{ item.machinemodel }}",
            "{{ item.machinecode }}",
            "{{ item.serialnumber }}",
            "{{ item.appearance }}",
            "{{ item.archtype }}",
            "{{ item.partition }}",
            "{{ item.storagesize }}",
            "{{ item.applevel }}",
            "{{ item.domains }}",
            "{{ item.netnote }}",
            "{{ item.gateway }}",
            "{{ item.mask }}",
            "{{ item.serviceport }}",
            "{{ item.ha }}",
            "{{ item.hbIP1 }}",
            "{{ item.hbIP2 }}",
            "{{ item.hardwarecharge }}",
            "{{ item.systemcharge }}",
            "{{ item.appcharge }}",
            "{{ item.managegateway }}",
            "{{ item.managemask }}",
            "{{ item.repairlevel }}",
            "{{ item.repairdate }}",
            "{{ item.note }}",
            "{{ item.dbinfo }}",
            "{{ item.middlewareinfo }}",
            "{{ item.nonsysusers }}",
        ]
            {% if not forloop.last %}
                ,
            {% endif %}
        {% endfor %}
    ]
}
我的ajax返回值包含中文。我想这是根本原因。 Ajax返回如下:

{
    sEcho: 1,
    iTotalRecords: 1178,
    iTotalDisplayRecords: 1178,
    aaData:"[

        [
            "",
            "王晴测试机(临时)",
            "197.1.5.206",
            "windows 2003 64bit",
            "FANGLTST",
            "4",
            "32",
            "100G",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "0",
            "False",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "None",
            "",
            "",
            "",
            "",
        ]

                ,


        [
            "",
            "Opsware测试",
            "197.1.4.201",
            "Redhat 64bit",
            "bsae",
            "1",
            "1",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "0",
            "False",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "None",
            "",
            "",
            "",
            "",
        ]

                ,


        [
            "",
            "预留分区",
            "N/A",
            "AIX 6.1",
            "N/A",
            "4",
            "32",
            "100G",
            "",
            "兆维II",
            "ZWII-B1-08",
            "DOWN",
            "S13/14",
            "",
            "199.0.34.173",
            "IBM",
            "志鸿英华",
            "PS702",
            "8406",
            "06DB59A",
            "刀片",
            "小型机",
            "",
            "",
            "",
            "",
            "",
            "",
            "255.255.255.0",
            "0",
            "False",
            "",
            "",
            "陈晓峰/毕伟光",
            "姜晓寒",
            "张元泉",
            "199.0.34.250",
            "255.255.255.0",
            "7*24*4",
            "None",
            "",
            "",
            "",
            "",
        ]

                ,


        [
            "",
            "Opsware测试",
            "197.1.4.202",
            "Redhat 64bit",
            "hpna",
            "8",
            "16",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "0",
            "False",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "None",
            "",
            "",
            "",
            "",
        ]

                ,


        [
            "",
            "预留分区",
            "",
            "AIX 6.1",
            "N/A",
            "2",
            "16",
            "100G",
            "",
            "兆维II",
            "ZWII-B1-08",
            "DOWN",
            "S13/14",
            "",
            "199.0.34.173",
            "IBM",
            "志鸿英华",
            "PS702",
            "8406",
            "06DB59A",
            "刀片",
            "小型机",
            "",
            "",
            "",
            "",
            "",
            "",
            "255.255.255.0",
            "0",
            "False",
            "",
            "",
            "陈晓峰/毕伟光",
            "姜晓寒",
            "张元泉",
            "199.0.34.250",
            "255.255.255.0",
            "7*24*4",
            "None",
            "",
            "",
            "",
            "",
        ]

                ,


        [
            "",
            "Opsware测试",
            "197.1.4.122",
            "",
            "opsware2",
            "0",
            "0",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "0",
            "False",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "None",
            "",
            "",
            "",
            "",
        ]

                ,


        [
            "",
            "开发机",
            "197.1.4.18",
            "HPUX 11.23",
            "cmbcux1",
            "4",
            "8",
            "2*300G",
            "",
            "兆维",
            "ZW-01-01",
            "N/A",
            "",
            "U16/19",
            "197.1.7.205",
            "HP",
            "志鸿英华",
            "rx4640",
            "AB370B",
            "SGH4617B1X",
            "标准机架",
            "小型机",
            "N/A",
            "",
            "",
            "内联",
            "",
            "197.1.4.250",
            "255.255.255.0",
            "0",
            "False",
            "",
            "",
            "杨杰",
            "张立新",
            "张小龙",
            "197.1.7.250",
            "255.255.255.0",
            "N/A",
            "十一月 19, 2009",
            "sapcool1",
            "DB2 9.5.0.5",
            "",
            "",
        ]

                ,


        [
            "",
            "Opsware测试",
            "197.1.4.123",
            "",
            "opsware3",
            "0",
            "0",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "0",
            "False",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "None",
            "",
            "",
            "",
            "",
        ]

                ,


        [
            "",
            "开发机",
            "197.1.4.24",
            "HPUX 11.23",
            "hpux3",
            "4",
            "8",
            "6*146G",
            "",
            "兆维",
            "ZW-01-01",
            "N/A",
            "",
            "U1/8",
            "197.1.7.206",
            "HP",
            "志鸿英华",
            "rx6600",
            "AD132A",
            "SGH4711KDR",
            "标准机架",
            "小型机",
            "N/A",
            "",
            "",
            "内联",
            "",
            "197.1.4.250",
            "255.255.255.0",
            "0",
            "False",
            "",
            "",
            "杨杰",
            "张立新",
            "胡汝能",
            "197.1.7.250",
            "255.255.255.0",
            "N/A",
            "四月 13, 2010",
            "None",
            ""DB2 9.1.0.1",
            "None",
            "None",
        ]

                ,


        [
            "",
            "Opsware测试",
            "197.1.4.127",
            "",
            "opsware4bb",
            "0",
            "0",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "0",
            "False",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "None",
            "",
            "",
            "",
            "",
        ]


    ]
}

嗯,你能把整个错误都贴出来吗?另外,如果你能准确地解释一下你想要实现的目标,我相信我们能为你提供更多帮助,因为这个解决方案似乎过于复杂(而且充满了空值)@Hassek Hi,谢谢你的回复!我已经解决了这个问题。确实存在格式错误:*“{{item.nonsysusers}}”,**其中应删除逗号。。。有太多的领域。。。