zoukankan
html css js c++ java
Python Web简单加法器的实现--Python
坚持写博客来记录学习过程,哪怕学习的东西多么简单!下面是python中cgi相关知识。
T
emplate.py
:
(模板引擎文件)
#模板引擎
def
start_response(resp=
"text/html"):
return
'Content-type: '+resp+
'
'
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 ")
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())
查看全文
相关阅读:
N的阶乘:高精度
蓝桥杯历届试题 连号区间数:枚举(含样例解释)
最大公共子串:DP
IncDec序列:差分+贪心
[ACM] hdu 1465 不容易系列之一(错排复习)
写给现在,写给未来
[ACM] hdu 2082 找单词 (母函数)
[ACM] poj 1146 ID Codes(字符串的下一个排列)
[ACM] hdu 2149 Public Sale (巴什博奕)
[ACM] hdu 1846 Brave Game (巴什博奕)
原文地址:https://www.cnblogs.com/qikeyishu/p/8544687.html
最新文章
【PAT】B1080 MOOC期终成绩(25 分)
【PAT】B1081 检查密码(15 分)
【PAT】B1082 射击比赛(20 分)
【PAT】1083 是否存在相等的差(20 分)
LeetCode Palindrome Partitioning
Vim简明教程【CoolShell】
NYOJ 20 吝啬的国度
NYOJ 18 The Triangle
树状数组求逆序数
数据结构之树状数组
热门文章
POJ 2991 Crane
M
POJ 2785 4 Values whose Sum is 0
POJ 3684 Physics Experiment
Digital Roots:高精度
Catch That Cow:BFS:加标记数组:不加标记数组
Switch Game :因子数
Just a Hook:线段树+区间修改
模板整合
小数第n位:高精度
Copyright © 2011-2022 走看看