当 javascript 尝试重新加载页面时,以下错误会从 Django 发送给我的顾问。
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 86, in run
[11/Aug/2012 22:30:23] "GET /posting/drafts HTTP/1.1" 200 2785
self.finish_response()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 127, in finish_response
self.write(data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 210, in write
self.send_headers()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 268, in send_headers
self.send_preamble()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 192, in send_preamble
'Date: %s\r\n' % format_date_time(time.time())
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 324, in write
self.flush()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 57954)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 582, in process_request_thread
self.finish_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/servers/basehttp.py", line 139, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 640, in __init__
self.finish()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 693, in finish
self.wfile.flush()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
据我了解,这意味着谷歌浏览器在服务器完成发送页面之前断开了连接。为什么?我该如何解决?
这是javascript(Noty是一个确认框插件。只要知道我在旁边放一个“ * * ”的东西是实际执行的代码):
function delete_draft(id, name) {
var text = 'Are you sure you want to delete "' + name + '"?'; //*********
var confirm = noty({
text: text,
layout: 'center',
type: 'confirm',
modal: true,
buttons: [
{addClass: 'btn btn-danger', text: 'Cancel', onClick: function($noty) {
$noty.close();
}
},
{addClass: 'btn btn-primary', text: 'Delete', onClick: function($noty) {
$.post('/ajax/drafts/delete', {id:id}, function(data) { //**********
document.location.reload(true); //*******
});
document.location.reload(true); //*******
}
}
]});
}
这是 Django 中的视图:
def is_draft_owner(id, user): # It might be a coincidence, but when I added this the problems started.
print "test"
if user.pk is Draft.objects.get(id = id).user_id:
return True
print "checl"
print user.id
print Draft.objects.get(id = id).user_id
return False
def document_delete(request):
if is_draft_owner(request.POST['id'], request.user):
draft = Draft.objects.get(id = request.POST['id'])
draft.delete()
return HttpResponse("done")