内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/2159795/django-request-post-does-not-contain-the-name-of-the-button-that-submitted-the-f
我有一个django表单与两个不同的提交按钮,在表单提交的视图,我需要知道什么提交按钮被按下并采取不同的行动相应.
从我所看到的提交按钮的名称或ID应该在request.POST字典的某个地方,但它不在那里!
这是我的形式的片段:
<form id="editPaperForm" action="{{paper.editURL}}" method="POST">
<input type="submit" name="savePaperButton" id="savePaperButton" value="Save and Send Later"/>
<input type="submit" name="sendPaperButton" id="sendPaperButton" value="Save and send"/>
...
</form>
在视图中:
... if 'sendPaperButton' in request.POST: return applicants_confirmSend(request, paperID) else: return applicants_home(request)
sendPaperButton从不在request.POST中,而另一个也不是,我应该在别的地方看吗?
我唯一的想法是在发送表单之前添加一个隐藏的字段并通过javascript进行修改,但是似乎有些冗余,因为我很确定数据应该在某处
谢谢!
不要忘记在表单的“按钮”或“输入类型=提交”字段中添加名称和值参数.我曾遇到同样的问题,让我疯狂.
总之,作为request.POST包含一个dict,你需要一个键和一个值.键对应于您的按钮的名称参数,并且dict的值与按钮的值相对应.
<button type="submit" value="preview">Preview</button>
不会在request.POST中反映(POST字典没有关键字!),而
<button type="submit" value="preview" name="preview">Preview</button>
将有一个关键“预览”与值“预览”.
代码日志版权声明:
翻译自:http://stackoverflow.com/questions/2159795/django-request-post-does-not-contain-the-name-of-the-button-that-submitted-the-f
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- JFinal-layui v1.4.0 发布,表单上传按钮、优化图表统计、表格弹窗
- 按钮穿透点击实现方式
- 如何更好的控制按钮样式
- 通过按钮单击保存PhpSpreadSheet
- 撸一款”灵动“的滑动按钮
- Android处理按钮重复点击
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
An Introduction to the Analysis of Algorithms
Robert Sedgewick、Philippe Flajolet / Addison-Wesley Professional / 1995-12-10 / CAD 67.99
This book is a thorough overview of the primary techniques and models used in the mathematical analysis of algorithms. The first half of the book draws upon classical mathematical material from discre......一起来看看 《An Introduction to the Analysis of Algorithms》 这本书的介绍吧!