gpt4 book ai didi

python - 谷歌应用引擎 (Python) : Using multiple forms on a single web page

转载 作者:行者123 更新时间:2023-11-28 22:45:05 25 4
gpt4 key购买 nike

我在一个网页上有两个表单,分别提交时其内容存储在两个不同的数据库中。

这是包含两种不同形式的源代码:

<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

关于python - 谷歌应用引擎 (Python) : Using multiple forms on a single web page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28929654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com