bottle通过request.body获取用户输入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from bottle import route,run,request
htmlst = """
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title><h2>你好</h2></title>
</head>
<body>
<form action="/info" method='POST'>
<label>ID</label> <input type = "text" name="id" />
<label>e-mail</label> <input type = "text" name="email" />
<input type="submit"/>
</form >
</body>
</html>
"""

#因为按钮绑定了/info,所以点击后会向函数发回一个请求
#也就是:点下按钮,执行 f()

@route('/')
def index():
return htmlst


@route('/info',method='POST')
def f():
id = request.forms.get('id')
email = request.forms.get('email')
return (id,email)


run(port=8088,debug=True,reloader=True)

转载请注明来源 https://tianweiye.github.io