Simple python + html + from --> to python script

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

    #1

    Simple python + html + from --> to python script

    Hello All,

    I am trying to get information from a form and send it to a python
    script without success..
    Here is my objective:

    User enters data in form --form send variables to python script -->
    script runs and output result.

    the form code

    <form method="post" action="/cgi-bin/script.py" name="coord">En tre com
    os dados <input name="data1"><b r>

    Entre com os dados <input name="data2"><b r>
    Vai magraum <button name="submete"> </button></form>

    In my script.py

    What I should have to print
    something like

    Hello the data1 + data 2 = ....

    ?

    Maybe I am stumbling in something very simple, but I cannot find some
    working example, and I am totally confused...
    Thanks in advance

  • Steve Holden

    #2
    Re: Simple python + html + from --&gt; to python script

    flit wrote:
    Hello All,
    >
    I am trying to get information from a form and send it to a python
    script without success..
    Here is my objective:
    >
    User enters data in form --form send variables to python script -->
    script runs and output result.
    >
    the form code
    >
    <form method="post" action="/cgi-bin/script.py" name="coord">En tre com
    os dados <input name="data1"><b r>
    >
    Entre com os dados <input name="data2"><b r>
    Vai magraum <button name="submete"> </button></form>
    >
    In my script.py
    >
    What I should have to print
    something like
    >
    Hello the data1 + data 2 = ....
    >
    ?
    >
    Maybe I am stumbling in something very simple, but I cannot find some
    working example, and I am totally confused...
    Thanks in advance
    >
    Untested, without error checking. Caveat emptor:

    import cgi
    import cgitb; cgitb.enable() # optional error handling

    form = cgi.FieldStorag e()

    d1 = form["data1"].value
    d2 = form["data2"].value

    print """\
    Content-type: text/plain

    Hello: the data were: %s and %s""" % (d1, d2)

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://holdenweb.blogspot.com
    Recent Ramblings http://del.icio.us/steve.holden

    Comment

    • flit

      #3
      Re: Simple python + html + from --&gt; to python script

      Man....
      Very thanks...
      I really try to find some source of good and simple and nothing..
      Many thanks you are a great help!

      Steve Holden wrote:
      flit wrote:
      Hello All,

      I am trying to get information from a form and send it to a python
      script without success..
      Here is my objective:

      User enters data in form --form send variables to python script -->
      script runs and output result.

      the form code

      <form method="post" action="/cgi-bin/script.py" name="coord">En tre com
      os dados <input name="data1"><b r>

      Entre com os dados <input name="data2"><b r>
      Vai magraum <button name="submete"> </button></form>

      In my script.py

      What I should have to print
      something like

      Hello the data1 + data 2 = ....

      ?

      Maybe I am stumbling in something very simple, but I cannot find some
      working example, and I am totally confused...
      Thanks in advance
      Untested, without error checking. Caveat emptor:
      >
      import cgi
      import cgitb; cgitb.enable() # optional error handling
      >
      form = cgi.FieldStorag e()
      >
      d1 = form["data1"].value
      d2 = form["data2"].value
      >
      print """\
      Content-type: text/plain
      >
      Hello: the data were: %s and %s""" % (d1, d2)
      >
      regards
      Steve
      --
      Steve Holden +44 150 684 7255 +1 800 494 3119
      Holden Web LLC/Ltd http://www.holdenweb.com
      Skype: holdenweb http://holdenweb.blogspot.com
      Recent Ramblings http://del.icio.us/steve.holden

      Comment

      • J. Clifford Dyer

        #4
        Re: Simple python + html + from --&gt; to python script

        A good starting place would be the documentation on python.org.

        In this case, the python library reference would have been helpful:



        Cheers,
        Cliff


        flit wrote:
        Man....
        Very thanks...
        I really try to find some source of good and simple and nothing..
        Many thanks you are a great help!
        >
        Steve Holden wrote:
        >flit wrote:
        >>Hello All,
        >>>
        >>I am trying to get information from a form and send it to a python
        >>script without success..
        >>Here is my objective:
        >>>
        >>User enters data in form --form send variables to python script -->
        >>script runs and output result.
        >>>
        >>the form code
        >>>
        >><form method="post" action="/cgi-bin/script.py" name="coord">En tre com
        >>os dados <input name="data1"><b r>
        >>>
        >>Entre com os dados <input name="data2"><b r>
        >>Vai magraum <button name="submete"> </button></form>
        >>>
        >>In my script.py
        >>>
        >>What I should have to print
        >>something like
        >>>
        >>Hello the data1 + data 2 = ....
        >>>
        >>?
        >>>
        >>Maybe I am stumbling in something very simple, but I cannot find some
        >>working example, and I am totally confused...
        >>Thanks in advance
        >>>
        >Untested, without error checking. Caveat emptor:
        >>
        >import cgi
        >import cgitb; cgitb.enable() # optional error handling
        >>
        >form = cgi.FieldStorag e()
        >>
        >d1 = form["data1"].value
        >d2 = form["data2"].value
        >>
        >print """\
        >Content-type: text/plain
        >>
        >Hello: the data were: %s and %s""" % (d1, d2)
        >>
        >regards
        > Steve
        >--
        >Steve Holden +44 150 684 7255 +1 800 494 3119
        >Holden Web LLC/Ltd http://www.holdenweb.com
        >Skype: holdenweb http://holdenweb.blogspot.com
        >Recent Ramblings http://del.icio.us/steve.holden
        >

        Comment

        • flit

          #5
          Re: Simple python + html + from --&gt; to python script

          Sorry but for a totally newbie the lib doccumentation doesnt help..
          The target audience for the docs are for "grown ups" programmers..
          I think I will do some tutorial, in baby steps...

          J. Clifford Dyer wrote:
          A good starting place would be the documentation on python.org.
          >
          In this case, the python library reference would have been helpful:
          >

          >
          Cheers,
          Cliff
          >
          >
          flit wrote:
          Man....
          Very thanks...
          I really try to find some source of good and simple and nothing..
          Many thanks you are a great help!

          Steve Holden wrote:
          flit wrote:
          >Hello All,
          >>
          >I am trying to get information from a form and send it to a python
          >script without success..
          >Here is my objective:
          >>
          >User enters data in form --form send variables to python script -->
          >script runs and output result.
          >>
          >the form code
          >>
          ><form method="post" action="/cgi-bin/script.py" name="coord">En tre com
          >os dados <input name="data1"><b r>
          >>
          >Entre com os dados <input name="data2"><b r>
          >Vai magraum <button name="submete"> </button></form>
          >>
          >In my script.py
          >>
          >What I should have to print
          >something like
          >>
          >Hello the data1 + data 2 = ....
          >>
          >?
          >>
          >Maybe I am stumbling in something very simple, but I cannot find some
          >working example, and I am totally confused...
          >Thanks in advance
          >>
          Untested, without error checking. Caveat emptor:
          >
          import cgi
          import cgitb; cgitb.enable() # optional error handling
          >
          form = cgi.FieldStorag e()
          >
          d1 = form["data1"].value
          d2 = form["data2"].value
          >
          print """\
          Content-type: text/plain
          >
          Hello: the data were: %s and %s""" % (d1, d2)
          >
          regards
          Steve
          --
          Steve Holden +44 150 684 7255 +1 800 494 3119
          Holden Web LLC/Ltd http://www.holdenweb.com
          Skype: holdenweb http://holdenweb.blogspot.com
          Recent Ramblings http://del.icio.us/steve.holden

          Comment

          • Bruno Desthuilliers

            #6
            [0T] Re: Simple python + html + from --&gt; to python script

            flit a écrit :
            Hello All,
            >
            I am trying to get information from a form and send it to a python
            script without success..
            Here is my objective:
            >
            User enters data in form --form send variables to python script -->
            script runs and output result.
            <OT topic="HTTP">
            If the script has side-effects (adding/updating/deleting database
            records, writing files, etc), the script should not "output results",
            but redirect to another url where the user can see these results.

            Else - if the script doesn't have side-effects (ie :a search form, ...),
            then the HTTP method should be "GET", not "POST".
            </OT>
            the form code
            >
            <form method="post" action="/cgi-bin/script.py" name="coord">En tre com
            os dados <input name="data1"><b r>
            >
            Entre com os dados <input name="data2"><b r>
            Vai magraum <button name="submete"> </button></form>
            <OT topic="HTML">
            button elements don't submit the form - they in fact don't do anything
            unless you attach behaviour to them with javascript. What you want here
            is an input type='submit'.

            Also, the "button" tag doesn't require a end tag.

            <form method="POST" action="/cgi-bin/script.py" name="coord">
            <label for="data1">Ent re com os dados</label>
            <input type="text" name="data1" id="data1"><br >

            <label for="data2">Ent re com os dados </label>
            <input type="text" name="data2" id="data2"><br >
            Vai magraum <input type="submit" name="submete">
            </form>
            </OT>

            (cf Steve's answer and the cgi module's doc for your problem)

            Comment

            • Steve Holden

              #7
              Re: [0T] Re: Simple python + html + from --&gt; to python script

              Bruno Desthuilliers wrote:
              flit a écrit :
              >
              >>Hello All,
              >>
              >>I am trying to get information from a form and send it to a python
              >>script without success..
              >>Here is my objective:
              >>
              >>User enters data in form --form send variables to python script -->
              >>script runs and output result.
              >
              >
              <OT topic="HTTP">
              If the script has side-effects (adding/updating/deleting database
              records, writing files, etc), the script should not "output results",
              but redirect to another url where the user can see these results.
              >
              Else - if the script doesn't have side-effects (ie :a search form, ...),
              then the HTTP method should be "GET", not "POST".
              </OT>
              >
              >>the form code
              >>
              >><form method="post" action="/cgi-bin/script.py" name="coord">En tre com
              >>os dados <input name="data1"><b r>
              >>
              >>Entre com os dados <input name="data2"><b r>
              >>Vai magraum <button name="submete"> </button></form>
              >
              >
              <OT topic="HTML">
              button elements don't submit the form - they in fact don't do anything
              unless you attach behaviour to them with javascript. What you want here
              is an input type='submit'.
              >
              Also, the "button" tag doesn't require a end tag.
              >
              <form method="POST" action="/cgi-bin/script.py" name="coord">
              <label for="data1">Ent re com os dados</label>
              <input type="text" name="data1" id="data1"><br >
              >
              <label for="data2">Ent re com os dados </label>
              <input type="text" name="data2" id="data2"><br >
              Vai magraum <input type="submit" name="submete">
              </form>
              </OT>
              >
              (cf Steve's answer and the cgi module's doc for your problem)
              So what problem were you talking about?

              regards
              Steve
              --
              Steve Holden +44 150 684 7255 +1 800 494 3119
              Holden Web LLC/Ltd http://www.holdenweb.com
              Skype: holdenweb http://holdenweb.blogspot.com
              Recent Ramblings http://del.icio.us/steve.holden

              Comment

              • Bruno Desthuilliers

                #8
                Re: [0T] Re: Simple python + html + from --&gt; to python script

                Bruno Desthuilliers wrote:
                (snip)
                <OT topic="HTML">
                (snip)
                Also, the "button" tag doesn't require a end tag.
                oops ! Sorry, your syntax was ok - button elements actually requires the
                end tag.

                my bad :(


                --
                bruno desthuilliers
                python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
                p in 'onurb@xiludom. gro'.split('@')])"

                Comment

                • J. Clifford Dyer

                  #9
                  Re: Simple python + html + from --&gt; to python script

                  Good point. I forget sometimes, because that's how I learned, but I
                  came in with some background in other scripting languages, so I guess I
                  knew what I was looking for.

                  Thanks.

                  Cliff

                  flit wrote:
                  Sorry but for a totally newbie the lib doccumentation doesnt help..
                  The target audience for the docs are for "grown ups" programmers..
                  I think I will do some tutorial, in baby steps...
                  >
                  J. Clifford Dyer wrote:
                  >A good starting place would be the documentation on python.org.
                  >>
                  >In this case, the python library reference would have been helpful:
                  >>
                  >http://docs.python.org/lib/lib.html
                  >>
                  >Cheers,
                  >Cliff

                  Comment

                  Working...