HTML form POST to a python script?

后端 未结 2 1445
醉酒成梦
醉酒成梦 2020-12-28 09:28

Does anyone know of any good resources for information on how to POST data from a HTML form over to a python script?

2条回答
  •  -上瘾入骨i
    2020-12-28 10:09

    For a very basic CGI script, you can use the cgi module. Check out the following article from the Python documentation for a very basic example on how to handle an HTML form submitted through POST:

    • Web Programming in Python : CGI Scripts

    Example from the above article:

    #!/usr/bin/env python
    
    import cgi
    import cgitb; cgitb.enable()  # for troubleshooting
    
    print "Content-type: text/html"
    print
    
    print """
    
    
    Sample CGI Script
    
    
    
      

    Sample CGI Script

    """ form = cgi.FieldStorage() message = form.getvalue("message", "(no message)") print """

    Previous message: %s

    form

    message:

    """ % message

提交回复
热议问题