Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.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
Django只能将str(而不是“list”)连接到str_Django - Fatal编程技术网

Django只能将str(而不是“list”)连接到str

Django只能将str(而不是“list”)连接到str,django,Django,Django只能将str(而不是“list”)连接到str 错误消息 我有一些这样的代码: function form_submit() { var arr_category = new Array(); var arr_lawyer = new Array(); var data = new Object(); $('input[name^="category_idx"]').each(function() { arr_category.pus

Django只能将str(而不是“list”)连接到str 错误消息

我有一些这样的代码:

function form_submit() {
    var arr_category = new Array();
    var arr_lawyer = new Array();
    var data = new Object();

    $('input[name^="category_idx"]').each(function() {
        arr_category.push($(this).val());
    });

    $('input[name^="lawyer_idx"]').each(function() {
        arr_lawyer.push($(this).val());
    });

    console.log("arr_category=="+arr_category);
    console.log("arr_lawyer=="+arr_lawyer);

    if (confirm('edit??') == true) {
        data.arr_category = arr_category;
        data.arr_lawyer = arr_lawyer;
        call_ajax('/admin/lawyer/recommend_add', data);
        //alert("arr_lawyer=="+arr_lawyer);
    }
}
我在jquery方面做得好吗? 查看console.log

arr_category==1,2,3,4,5,6,7,8,9
arr_lawyer==64,37,57,58,130,62,38,51,110
admin_view.py

@csrf_exempt
def recommend_add(request):

    print("TEST BANG VALUE------------")
    if request.is_ajax() and request.method == "POST":

        arr_category = request.GET.getlist('arr_category[]')
        print("arr_category------------" + arr_category)

    code = 0
    msg = "TEST."

    data = json.dumps({
        'code': code,
        'msg': msg,
        #'retURL': retURL

    })
    return HttpResponse(data, content_type='application/json')
我想打印。 错误消息 TypeError:只能将str(而不是“列表”)连接到str


我如何才能做到这一点?

在打印代码中,请尝试以下操作

print("arr_category------------:", arr_category)

如果希望将python解释器错误消息返回到jquery的ajax调用,那么可以使用以下语法

def recommend_add(request):
 print("TEST BANG VALUE------------")
 if request.is_ajax() and request.method == "POST":
   try:
     arr_category = request.GET.getlist('arr_category[]')
     print("arr_category------------" + arr_category)
     code = 0
     msg = "Success"
   except Exception as e:
     code = '' # anything you want as per your internal logic in case of error.
     msg = str(e)

 data = json.dumps({
    'code': code,
    'msg': msg,
    #'retURL': retURL

 })
 return HttpResponse(data, content_type='application/json')

请忽略我的缩进。

Print-->arr_category---------:[]在函数中发布数据对象,以便在函数中检查是否发布了数据。请尝试此数据=请求。发布['data'],然后打印数据。arr_类别为空,因为您没有发布arr_类别。在post块中,您还有request.GET