我很困惑我有这个问题,我希望有人能指出我的错误。Django:POST方法后重定向到当前页面显示重新发布警告
我在views.py中有一个方法,它绑定到一个具有表单的模板。代码如下所示:
def template_conf(request, temp_id):
template = ScanTemplate.objects.get(id=int(temp_id))
if request.method == 'GET':
logging.debug('in get method of arachni.template_conf')
temp_form = ScanTemplateForm(instance=template))
return render_response(request, 'arachni/web_scan_template_config.html',
{
'template': template,
'form': temp_form,
})
elif request.method == 'POST':
logging.debug('In post method')
form = ScanTemplateForm(request.POST or None, instance=template)
if form.is_valid():
logging.debug('form is valid')
form.save()
return HttpResponseRedirect('/web_template_conf/%s/' %temp_id)
此页面的行为是这样的:当我按下“提交”按钮,程序进入POST
分公司,并成功地执行在分支机构的一切。然后HttpResponseRedirect
只重定向到当前页面(该url是当前网址,我认为应该等于.
)。之后,GET
分支自我重定向到当前页面后被执行,并且页面成功返回。但是,如果我刷新页面,此时,浏览器返回一个确认警告:
The page that you're looking for used information that you entered.
Returning to that page might cause any action you took to be repeated.
Do you want to continue?
如果我确认,POST数据将被张贴到后端一次。看起来像浏览器仍然保存着以前的POST数据。我不知道为什么会发生这种情况,请帮助。谢谢。
+1我有完全相同的问题。我有类似的代码,但它似乎只能在Firefox中正常工作。 – 2013-03-08 16:21:45
@KevinDiTraglia:哦,我以前没有尝试过Firefox,但看起来像firefox做的工作。很奇怪...... – 2013-03-08 16:26:36
@KevinDiTraglia这是Chrome 25中的一个错误,请参阅下面的答案。 – Alasdair 2013-03-10 15:33:48