Casey Bralla on 1 Sep 2013 14:12:46 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Problems of GET and POST methods in Python


You only showed a code snippet, but did you close the form with a </form> 
statement?   Sometimes if you have unbalanced html, weird things happen.

Otherwise, I don't see anything wrong with what you are doing.  I often switch 
from "post" to get" and back again.  Having the data on the URL line aides in 
debugging, but looks crummy for users.

If you like, I would be happy to review your entire file and see if I see 
anything goofy.



On Thursday, 2013-08-29 7:30:27 PM Mahboob Khokhar wrote:
> Anyone can help for this post?
> 
> 
> File name *mypage.py*
> 
> Python code
> 
> form = cgi.FieldStorage()
> 
> name = form.getfirst('name', 'empty')
> id   = form.getfirst('id', 'empty')
> print """\
>     Content-Type: text/html\n
>     <html>
>     <body>
>         <p>Name: "%s"</p>
>         <p>ID: "%s"</p>
>     </body>
>     </html>
>     """ % (name, id)
> 
> HTML inside the same file
> 
> <form name="frm" method="post" action="mypage.py?id=33"><input
> type="text" name="name" value="MyName" /><input type="Submit" id="btn"
> value="Send" />
> 
> After submitting the form (pressing Send button), I can see this URL with
> following output
> 
>   localhost:8000/cgi-bin/mypage.py?id=33
> 
>   Name: "empty"
>   ID: "33"
> 
> if I change the form method POST to GET
> 
> <form name="frm" method="get" action="mypage.py?id=33">
> 
> then I can see this URL with following output
> 
> localhost:8000/cgi-bin/mypage.py?name=MyName
> Name: "MyName"
> ID: "empty"
> 
> I don't understand why I am not receiving text field value with POST method
> ? And why I am unable to receive id value in query string with GET method ?
> 
> Its simple python page without any framework. BTW I am using
> "python-bugzilla 0.8.0" downloaded
> fromhere<https://pypi.python.org/pypi/python-bugzilla>
>  but i think my given code is just a simple page and has nothing to do with
> this package.
> 
> Any help would be appreciated.
> 
> Thanks in advance,
> 
> http://stackoverflow.com/questions/18516315/problems-of-get-and-post-methods
> -in-python

-- 

Casey Bralla

Chief Nerd in Residence
The NerdWorld Organisation
www.NerdWorld.org
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug