返回无效表单时如何维护下一个参数?
(由于各种原因,我还不想实现 ajax)
这是我的观点的代码:
def registration(request):
if request.method == 'POST':
form = MyForm(request.POST)
redirect_to = request.REQUEST.get('next','')
if form.is_valid():
#Do stuff
return HttpResponseRedirect(redirect_to if redirect_to != ''
else reverse('named_url'))
#Next parameter lost here!!
return render(request, 'registration.html', {'form' : form})
else:
return render(request, 'registration.html', {'form' : MyForm()})