CGI Programming in Python
The Common Gateway Interface (CGI) is a standard for writing programs that can interact through a Web server with a client running a Web browser.
- CGI is the standard for programs to interface with HTTP servers.
- CGI programming is written dynamically generating webpages that respond to user input or webpages that interact with software on the server
Install apache2 on your system can we will run ‘hello.py’ on host ‘127.0.0.1’
It is recommended to have basic knowledge of HTML before trying this example.
hello.py
#!/usr/bin/python3 # Importing the 'cgi' module import cgi print("Content-type: text/html\r\n\r\n") print("<html><body>") print("<h1> Hello Program! </h1>") # Using the inbuilt methods form = cgi.FieldStorage() if form.getvalue("name"): name = form.getvalue("name") print("<h1>Hello" +name+"! Thanks for using my script!</h1><br />") if form.getvalue("happy"): print("<p> Yayy! I'm happy too! </p>") if form.getvalue("sad"): print("<p> Oh no! Why are you sad? </p>") # Using HTML input and forms method print("<form method='post' action='hello2.py'>") print("<p>Name: <input type='text' name='name' /></p>") print("<input type='checkbox' name='happy' /> Happy") print("<input type='checkbox' name='sad' /> Sad") print("<input type='submit' value='Submit' />") print("</form") print("</body></html>") |
chevron_right
filter_none
This article is contributed by Harsh Wardhan Chaudhary (Intern). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Recommended Posts:
- Python in Competitive Programming
- Turtle Programming in Python
- Socket Programming in Python
- A basic Python Programming Challenge
- Python | Linear Programming in Pulp
- Difference Between Go and Python Programming Language
- Socket Programming with Multi-threading in Python
- Python - Fastest Growing Programming Language
- Python Input Methods for Competitive Programming
- Command Line Interface Programming in Python
- Why is Python the Best-Suited Programming Language for Machine Learning?
- Object Oriented Programming in Python | Set 2 (Data Hiding and Object Printing)
- Object Oriented Programming in Python | Set 1 (Class, Object and Members)
- 5 Best Programming Languages For Newbies
- Comparison of Java with other programming languages
Improved By : nidhi_biet


