problem running the cgi module

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chris patton

    #1

    problem running the cgi module

    Hi everyone. I'm trying to code an HTML file on my computer to make it
    work with the cgi module. For some reason I can't get it running. This
    is my HTML script:

    ------------------------------------------------------

    <form method="post" action="C:\chri s_on_c\hacking\ formprinter.py" >
    <b><i><font size="50">HOWDY !</font></b></i><br><br>

    <input type="text" name="name" size="50" value=""><br><b r>

    <input type="submit" name="send" value="submit">
    </form>

    ------------------------------------------------------

    And here is the python program it's supposed to run with,
    formprinter.py:

    ------------------------------------------------------

    import cgi, cgitb
    cgitb.enable()

    form = cgi.FieldStorag e()
    print '<font size="12">%s</font><br>' % form['name']

    ------------------------------------------------------

    Whenever I press submit on the HTML document, it returns the code for
    "formprinter.py ". Can someone tell me what I'm doing wrong?

    -Thanks for any help!

  • pythonUser_07

    #2
    Re: problem running the cgi module

    I will take a guess that you might
    1) make sure cgi is enabled in your webserver configuration
    2) Probably must place the cgi script under $WEBSERVERDOCS/cgi-bin
    unless you alter the configuration.

    Also, the webserver might need to be configured to understand what
    interpreter uses .py files. (not an issue on windows)

    Good luck

    Comment

    • chris patton

      #3
      Re: problem running the cgi module

      Thanks for the help.

      Comment

      • Kent Johnson

        #4
        Re: problem running the cgi module

        chris patton wrote:[color=blue]
        > Hi everyone. I'm trying to code an HTML file on my computer to make it
        > work with the cgi module. For some reason I can't get it running. This
        > is my HTML script:
        >
        > ------------------------------------------------------
        >
        > <form method="post" action="C:\chri s_on_c\hacking\ formprinter.py" >
        > <b><i><font size="50">HOWDY !</font></b></i><br><br>
        >
        > <input type="text" name="name" size="50" value=""><br><b r>
        >
        > <input type="submit" name="send" value="submit">
        > </form>[/color]

        You don't seem to be using a web server at all here - the form action is a file path, not a URL. So
        the browser is just going to the file system to get the .py file.

        You can make a simple CGI server by
        - create a directory caled cgi-bin
        - put formprinter.py into it
        - change the form action to action="/cgi-bin/formprinter.py"
        - Open a dos console to the directory containing the cgi-bin directory
        - run the command python -c "import CGIHTTPServer; CGIHTTPServer.t est()"

        (Don't do this with Python 2.4, it is broken - use 2.3 or 2.4.1)

        Kent
        [color=blue]
        >
        > ------------------------------------------------------
        >
        > And here is the python program it's supposed to run with,
        > formprinter.py:
        >
        > ------------------------------------------------------
        >
        > import cgi, cgitb
        > cgitb.enable()
        >
        > form = cgi.FieldStorag e()
        > print '<font size="12">%s</font><br>' % form['name']
        >
        > ------------------------------------------------------
        >
        > Whenever I press submit on the HTML document, it returns the code for
        > "formprinter.py ". Can someone tell me what I'm doing wrong?
        >
        > -Thanks for any help!
        >[/color]

        Comment

        • chris patton

          #5
          Re: problem running the cgi module

          Thanks alot. This helps tremendously

          Comment

          Working...