- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Passing Information using GET method in Python
The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character as follows −
The GET method is the default method to pass information from browser to web server and it produces a long string that appears in your browser's Location:box. Never use GET method if you have password or other sensitive information to pass to the server.
The GET method has size limitation: only 1024 characters can be sent in a request string. The GET method sends information using QUERY_STRING header and will be accessible in your CGI Program through QUERY_STRING environment variable.
You can pass information by simply concatenating key and value pairs along with any URL or you can use HTML <FORM> tags to pass information using GET method.
Simple URL Example:Get Method
Here is a simple URL, which passes two values to hello_get.py program using GET method.
Below is hello_get.py script to handle input given by web browser. We are going to use cgi module, which makes it very easy to access passed information −
#!/usr/bin/python # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields first_name = form.getvalue('first_name') last_name = form.getvalue('last_name') print "Content-type:text/html\r\n\r\n" print "<html>" print "<head>" print "<title>Hello - Second CGI Program</title>" print "</head>" print "<body>" print "<h2>Hello %s %s</h2>" % (first_name, last_name) print "</body>" print "</html>"
This would generate the following result −
Hello ZARA ALI
Simple FORM Example:GET Method
This example passes two values using HTML FORM and submit button. We use same CGI script hello_get.py to handle this input.
<form action = "/cgi-bin/hello_get.py" method = "get"> First Name: <input type = "text" name = "first_name"> <br /> Last Name: <input type = "text" name = "last_name" /> <input type = "submit" value = "Submit" /> </form>
Here is the actual output of the above form, you enter First and Last Name and then click submit button to see the result.
- Passing Information Using POST Method in Python
- How to get a file system information using Python?
- How to get service information with the WMI method using PowerShell?
- Passing to method geticon in SAPUI5
- Passing array to method in Java
- Resource Usage Information using Python
- How to get complete drive information using C#?
- How to get the disk information using PowerShell?
- Get the Machine limits information for integer types in Python
- Get the Machine limits information for float types in Python
- get() method for dictionaries in Python
- How to get the system configuration information relevant to an open file using Python?
- How to get month information in android using yearmonth API class?
- Get current time information in Java