使用 python 处理提交的表单 3.



我正在尝试编写一个快速的HTML表单:

<!DOCTYPE html>
<html>
    <head>
        <title>some title</title>
    </head>
    <body>
    <form method="post" action="filename.cgi">
          Deploy Process Name:<br>
    <input type="text" name="deploy_process_name"><br>
    <input type="submit" name="submitXML" value="Submit XML"/>
    </form>
    </body>
</html>

我使用 cgi 包用 python 编写了以下脚本,以从表单中提取数据并对其进行处理:例如 - 获取deploy_process_name

import cgi
def htmlTop():
    print("""Content-type:text/htmlnn
    <!DOCTYPE html>
    <html lange="en">
        <head>
            <title>Title</title>
        </head>
        <body>""")
def htmlTail():
    print("""</body>
        </html>""")
def getData():
    formData = cgi.FieldStorage()
    deploy_pro_name= formData.getvalue("deploy_process_name")
    return deploy_pro_name
if __name__ == '__main__':
    try:
        htmlTop()
        depl= getData()
        print("DeployProcessName= {}".format(depl))
        htmlTail()
    except:
        cgi.print_exception()

当我单击提交时,它只是下载文件名.cgi。如何让它在点击提交后运行以下脚本?

似乎您错误地设置了服务器端。请遵循您的服务器端CGI提供的信件(无论是apache httpd,nginx,lighttpd还是其他什么(

需要关注的事项:

  • 脚本文件夹的所有权(用户:组(
  • 脚本文件夹的权限
  • 脚本的所有权(用户:组(
  • 脚本的权限

您似乎使用了默认扩展,但是您是否确保已加载CGI模块并使用该扩展来处理CGI?

最新更新