使用jQuery post发布Django视图返回错误

时间:2013-12-01 10:32:43

标签: javascript jquery python ajax django

我对Django视图进行了以下JavaScript jQuery AJAX调用:

$.post('/accounts/ajax/user_verification/', data)
    .done( user_verification_cb )
    .fail( console.log('user_verification POST failed') );

...... Django观点:

@json_view
@login_required
def user_verification(request):

    value = unicode(request.POST['user_list'])
    user_list = json.loads(value)

    v_users = []

    for user_id in user_list:

        v_users.append(user_id)

    j_v_users = json.dumps(v_users)
    result = dict(user_list = j_v_users)

    print (__name__ + ', user_verification, j_v_users = ' + j_v_users)

    return result

我得到以下输出(j_v_users变量):

accounts.ajax, user_verification, j_v_users = ["42"]

在JavaScript中,“.fail()”承诺总是被调用。此外,我总是使用Django开发服务器获得以下异常:

Exception happened during processing of request from ('127.0.0.1', 50211)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 593, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/home/rtubio/repositories/satnet-release-1/WebServices/__v_env/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 150, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/lib/python2.7/SocketServer.py", line 651, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 704, in finish
    self.wfile.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

我知道这个异常可能是Django开发服务器的内部错误。但是,我不知道这是否会引发返回jQuery $ .post()的问题。

0 个答案:

没有答案