通过URL传递参数给python(加减法) 作者:xieaotian发表于2009-05-27 10:40:35
重点:
1.urls的设置:
urls=('','index'
)<----------后半括号必须缩进,不要加多余的逗号分隔符,当第一个元素为"/"或者"/..."时,访问地址的参数加在/或者/...目录后面.
2.格式转换
由于从url上得到的输入都是字符串形式的不能直接相加减所以必须转换
利用python的string模块
import string;
num=string.atoi("")<-------将字符串转换.
3.如何显示
必须用web.header()方法,告诉python用什么格式显示
例:web.header('Content-type', 'text/html')
例子:
import string
import web
from Cheetah.Template import Template
urls = (
'', 'index'
)
class index:
def GET(self):
Get=web.input()
value1=Get.a;value2=Get.b
num=string.atoi(value1);num1=string.atoi(value2)
value3=num+num1
x={};
x['value']=value3
web.header('Content-type', 'text/html')
template=Template(file='E:/xx.html',searchList=[x])
print template,
application = web.wsgifunc(web.webpyfunc(urls, globals()))
web.webapi.internalerror = web.debugerror
if __name__ == "__main__": web.run(urls, globals())
E:\xx.html:
Abuot Yeef
About $!name
Value:$value
