将html表单值发布到python脚本

编程入门 行业动态 更新时间:2024-10-28 10:27:22
本文介绍了将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脚本

本文发布于:2023-10-10 12:24:27,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   脚本   html   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!