insist on blogging to record the learning process, even if you learn how simple! The following is the CGI-related knowledge in Python.
T
emplate.py:(Template engine file)#模板引擎
DefStart_response (resp="Text/html"):
Return' Content-type: ' +resp+‘\ n‘
DefStart_form (the_url="", form_type="POST"):
Return' <form action= ' +the_url+' "method=" ' +form_type+' > '
DefEnd_form (submit_msg="Sum"):
Return' <input type= ' submit "value=" ' +submit_msg+' > '
DefInput_label (name, placeholder="", value="", readonly=None):
If ReadOnlyis None:
Return' <input type= ' "text" size= "value=" ' +value+' "Name=" ' +name+' "placeholder=" ' +placeholder+' > '
Else
Return' <input type= ' "text" size= "value=" ' +value+' "readonly=" ' +readonly+' "Name=" ' +name+' "placeholder=" ' +placeholder+' > '
DefContext (Word):
return word
def start_div (Align,style):
"<div align=" ' +align+ "" style= "' +style+< Span style= "color: #6a8759;" > ' > '
">
main.py:Import CGITBCgi
From TemplateImport *
form1=cgi. Fieldstorage ()
Num1=form1.getvalue ("Num1")
Num2=form1.getvalue ("Num2")
num3=None
If not NUM1is None and not num2is None:
num1=Int (NUM1)
Num2=Int (num2)
Num3=num1+num2
# print ("content-type:text/html \ n \ nthe")
Print (Start_response ())
# Print (IMG (".. /views/add.png "))
# Print (Start_div ("center", "margin-top:40px;"))
# Print (IMG (".. /views/add.png "))
# Print (End_div ())
Print (Start_div ("Center","margin:50px 0 0 0"))
Print (Start_form ())
Print (Input_label ("Num1","Parameter 1"))
Print"+")
Print (Input_label ("Num2","Parameter 2"))
Print"=")
if num3 is None:
"Num3" , "" , "ReadOnly"))
else:
"Num3" ,str (num3) , "ReadOnly"))
print (End_form ())
print (End_div ())
Python Web Simple adder Implementation--python