坚持写博客来记录学习过程,哪怕学习的东西多么简单!下面是python中cgi相关知识。
Template.py:(模板引擎文件)
#模板引擎
def start_response(resp="text/html"):
return 'Content-type: '+resp+ '\n\n'
def start_form(the_url="",form_type="POST"):
return '<form action="'+the_url+'"method="'+form_type+'">'
def end_form(submit_msg="求和"):
return '<input type="submit" value="' +submit_msg+'">'
def input_label(name,placeholder="",value="",readonly=None):
if readonly is None:
return '<input type="text" size="20" value="'+value+'" name="'+name+'" placeholder="'+placeholder+'">'
else:
return '<input type="text" size="20" value="'+value+'" readonly="'+readonly+'" name="'+name+'" placeholder="'+placeholder+'">'
def context(word):
return word
def start_div(align,style):
return '<div align="'+align+'"style="'+style+'">'
def end_div():
return "</div>"
def img(src):
return '<img src="'+src+'">
main.py:
import cgitb,cgi
from Template import *
form1=cgi.FieldStorage()
num1=form1.getvalue("Num1")
num2=form1.getvalue("Num2")
num3=None
if not num1 is None and not num2 is None:
num1=int(num1)
num2=int(num2)
num3=num1+num2
# print("Content-type:text/html \n\n")
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","参数1"))
print("+")
print(input_label("Num2","参数2"))
print("=")
if num3 is None:
print(input_label("Num3","结果","","readonly"))
else:
print(input_label("Num3", "结果",str(num3), "readonly"))
print(end_form())
print(end_div())
![](data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCABVAbsDAREAAhEBAxEB/8QAHQABAAIDAAMBAAAAAAAAAAAAAAYHAwUIAQIECf/EADsQAAEDAw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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//ZAA==)
posted @
2018-03-11 16:48
牛新龙的IT技术博客
阅读(
1620)
评论()
编辑
收藏
举报