如何将 html 表单的名称/文件名传递给 python - CGI / HTML / Python

How to pass the name of the html form / filename to python - CGI / HTML / Python

我在网上和 Whosebug 上搜索了一堆,仍然没有找到答案。

我有两个 HTML 表单 something.html(针对用户)和 something_test.html(针对合作开发者),它们都将表单中的输入传递给相同的 python 脚本使用 POST。我的问题是我如何知道 python 脚本中哪个 HTML 表单发送了输入?在我的例子中,如果它是 'something_test.html',那么显示的输出将更加冗长。

表单名称是否存储在我可以在 python 脚本中解析的某个变量中。

在此先感谢您的帮助。

好的,假设您已经能够解析表单数据...

我会像这样向您的表单添加一个隐藏的输入字段:

something.html

<input type="hidden" id="formName" name="name_of_form" value="something">

something_test.html

<input type="hidden" id="formName" name="name_of_form" value="something_test">

然后在您的 python 脚本中处理表单数据时,表单的名称将在 "name_of_form" 中可用。