将html表单值发布到python脚本 [英] Posting html form values to python script

查看:95
本文介绍了将html表单值发布到python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了带有文本框和按钮的html表单



输入您的搜索关键字



我的要求是将文本框的值传递给我的test.py代码,有没有办法做到这一点。
请告诉我它是如何做到的。 ,放置你的CGI脚本的位置,文本框的值将被传递给CGI脚本。
eg。

 < form name =searchaction =/ cgi-bin / test.py方法= GET > 
搜寻:< input type =textname =searchbox>
< input type =submitvalue =提交>
< / form>

在您的test.py中

  import cgi 
form = cgi.FieldStorage()
searchterm = form.getvalue('searchbox')

因此,您将在python的searchterm变量的搜索文本框中输入关键字。


I have created html form with text box and button

enter ur search keyword

My requirement is to pass the text box value in to my test.py code, is there any way to do it. Please suggest me how do it.

解决方案

in the form action form action="", put the location of your cgi script and the value of the textbox will be passed to the cgi script. eg.

<form name="search" action="/cgi-bin/test.py" method="get">
Search: <input type="text" name="searchbox">
<input type="submit" value="Submit">
</form> 

in your test.py

import cgi
form = cgi.FieldStorage()
searchterm =  form.getvalue('searchbox')

thus you will get the key word entered in search text box in searchterm variable in python.

这篇关于将html表单值发布到python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆