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())
查看全文
相关阅读:
7.3形成团队结构
第7章 设计构架
第6章 空中交通管制:高可用性设计案例分析
5.5安全性战术
第5章实现质量属性
4..4.7 使用一般场景进行沟通的概念
4.4.3性能
第II部分创建构架
3.3.2使用结构
docker容器互联
原文地址:https://www.cnblogs.com/qikeyishu/p/8544687.html
最新文章
First-Spike-Based Visual Categorization Using Reward-Modulated STDP
A review of learning in biologically plausible spiking neural networks
Networks of Spiking Neurons: The Third Generation of Neural Network Models
Bag of Tricks for Image Classification with Convolutional Neural Networks
MS-SSIM与GDN层的PyTorch实现
华为云配置Objected-based Storage System
Intriguing properties of neural networks
Linux MPI环境配置
常用生成模型代码大全(pytorch/tensorflow)
多文档
热门文章
堆栈窗口
停靠窗口
滑块数字的使用
各种进度条的使用
基本布局的管理
进度条的使用
表格的使用
各类消息框的使用
实现QQ抽屉效果
第8章 飞行模拟:构架可集成性案例分析
Copyright © 2011-2022 走看看