我正在使用Django.我有一个
HTML页面,我在那里做一些
Javascript的东西,然后我用这种方式做一个jQuery帖子:
$.ajax({
url: '/xenopatients/measurement/qual',type: 'POST',data: {'obj':data},dataType: 'json',contentType: "application/json; charset=utf-8",//questo ok
});
在此帖子请求之后,我的Django视图正确处理了此URL的调用.
我想要它做的是处理数据,将用户发送到另一页,并将此数据发送到新页面.
问题是我不能像往常一样在Python中执行重定向,就像代码忽略重定向一样.
我的Python代码是:
@csrf_protect
@login_required#(login_url='/xenopatients/login/')
def qualMeasure(request):
name = request.user.username
print "enter"
if request.method == 'POST':
print request.POST
if "obj" in request.POST:
print 'obj received'
return render_to_response('mice/mice_status.html',RequestContext(request))
return render_to_response('measure/qual.html',{'name': name,'form': QualMeasureForm()},RequestContext(request))
我发现更改页面的唯一方法是在上面的代码之后通过Javascript:
top.location.href = "/xenopatients/measurement";
但是我不知道在使用这种方法时如何传递我需要的数据.
document.measureForm.id_barcode.focus();
document.measureForm.Add.disabled = false;
$('#dataTable').tablePagination({});
附:我也试过$.post,但结果相同.
在Django中使用jQuery发出请求后,如何进行重定向?