Ajax不会重定向页面!
从重定向中获得的是POST响应中数据对象内部新页面中的html代码。
如果您知道在任何操作失败后将用户重定向到何处,则只需执行以下操作:
在服务器上,
万一你有一个错误
response = {'status': 0, 'message': _("Your error")}如果一切顺利
response = {'status': 1, 'message': _("Ok")} # for ok发送响应:
return HttpResponse(json.dumps(response), content_type='application/json')
在html页面上:
$.post( "{% url 'your_url' %}", { csrfmiddlewaretoken: '{{ csrf_token}}' , other_params: JSON.stringify(whatever) },function(data) { if(data.status == 1){ // meaning that everyhting went ok // do something } else{ alert(data.message) // do your redirect window.location('your_url') } });如果您不知道将用户发送到哪里,并且希望从服务器获取该网址,只需将其作为参数发送:
response = {'status': 0, 'message': _("Your error"), 'url':'your_url'}然后将其替换为窗口位置:
alert(data.message) // do your redirect window.location = data.url;



