我在一个网页上有两种形式,分别提交时,其内容将存储在两个不同的数据库中。
这是包含两种不同形式的源代码:
<form method = "post">
To:<input type = "text" name = "to"><br>
Amt:<input type = "text" name = "to_amt"> <br>
<input type = "submit">
</form>
<br>
<form method = "post">
By:<input type = "text" name = "by"><br>
Amt:<input type = "text" name = "by_amt"> <br>
<input type = "submit">
</form>
现在,当我从网页提交表单时,我所关心的处理程序将如何知道调用哪个表单的post方法?在main.py文件中提交一种表单的内容时,如何区分两种表单?
PS:我不想根据我提交的表单将应用程序的控件重定向到两个不同的URL。还有其他替代解决方案吗?
添加一个隐藏字段来标识提交的表单,然后适当地分支代码。
带注释的形式:
<form method = "post">
To:<input type = "text" name = "to"><br>
Amt:<input type = "text" name = "to_amt"> <br>
<input type = "hidden" name = "form_name" value = "first">
<input type = "submit">
</form>
然后只需签入您的处理程序即可:
def post(self):
if self.request.get('form_name') == 'first':
# the first form was submitted
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句