Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Using CGI with Python and HTML forms

#!/usr/bin/python3
# Importing the 'cgi' module
import cgi
  
  
print("Content-type: text/html

")
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>")
Comment

PREVIOUS NEXT
Code Example
Python :: the rest of steps in the link below 
Python :: how to run another python file in python 
Python :: python map and filter 
Python :: hash tables in python 
Python :: Lists and for loops in python 
Python :: django command to fetch all columns of a table 
Python :: nums: List[int] in python function 
Python :: signup generic 
Python :: check two list python not match 
Python :: in np array how to make element as 1 if it exceeds the threshold 
Python :: setheading in python 
Python :: mylist = [“hello”, “bye”,”see ya”,”later”] phrase = mylist[1] 
Python :: python initialize a 2d array 
Python :: distplot for 2 columns 
Python :: save gif python 
Python :: gcp jupyter use python variables in magic bigquery 
Python :: comment faire un long commentaire en python 
Python :: try finally return precedent 
Python :: create a list with user defined name of list 
Python :: Python String Membership 
Python :: numpy fancy indexing 
Python :: encrypt 
Python :: winwin 
Python :: rom requests_html import HTML 
Python :: .text xpath lxml 
Python :: the most effective search methods in python with example 
Python :: python loop take out element backwardly 
Python :: Customizing plot with axes object 
Python :: call static method from another static method python 
Python :: how to make a value 0 if its negatice 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =