install web.py 接口框架用到的包html
http://webpy.org/tutorial3.zh-cn 官方网址python
http://webpy.org/tutorial3.zh-cnweb
学学服务端编程的主题编程
pip install web.py服务器
Urls=()路由app
App表示路由在程序应用里全局生效框架
类里定义访问跟程序的对应关系,就是路由post
def Get 表示对GET的请求作处理学习
Action表单元素的value所提交的网页,用来验证捕获get或post的值是否正确,例如帐户信息ui
# -*- coding: utf-8 -*-
import web
from web import form
import cgi
#动态的往模板(templates是一个静态网页)里填充数据
render = web.template.render('templates/')
路由,访问跟程序的对应关系
urls = (
#’http://127.0.0.1:8080/’默认没加任何地址,会调用下边的index类的GET方法
'/', 'index',
#’http://127.0.0.1:8080/interface’加了/interface,会调用下边的interface类的GET或post方法
'/interface', 'interface'
)
app = web.application(urls, globals())
class index:
def GET(self):
#return "Hello, world!"
#print "hello world"
#form = myform()
# make sure you create a copy of the form by calling it (line above)
# Otherwise changes will appear globally
#print(form.render())
return render.formtest()#返回模板页面,没有任何东西
class interface:
def GET(self): return "hi"
def POST(self):
i = web.input()#是一个字典
print “i:”,i
return 'form value:',i.title#把字典key名为title的值给取到
if __name__=="__main__":
web.internalerror = web.debugerror
app.run()
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>haha</title>
</head>
<body>
<form method="post" action="interface">
<p><input type="text" name="title" /> <input type="submit" value="submit" /></p>
</form>
</body>
</form>
</html>
D:\test\study>python interface_index.py
http://127.0.0.1:8080/interface
# -*- coding: utf-8 -*-
import web
from web import form
import cgi
render = web.template.render('templates/')
#路由
urls = (
'/', 'index',
'/interface', 'interface'
)
app = web.application(urls, globals())
class index:
def GET(self):
#return "Hello, world!"
#print "hello world"
#form = myform()
# make sure you create a copy of the form by calling it (line above)
# Otherwise changes will appear globally
#print(form.render())
return render.formtest()
class interface:
def GET(self): return "hi"
def POST(self):
i = web.input()
print "i:",i
return 'form value:',i.title,i #form value是字符串
if __name__=="__main__":
web.internalerror = web.debugerror
app.run()
后台:
i: <Storage {'title': u'helloxia'}>
127.0.0.1:49925 - - [18/Jun/2018 22:36:05] "HTTP/1.1 POST /interface" - 200 OK
这就是介绍了一下服务器端是怎么工做的