想利用python的bottle设计一个调查问卷,第一次接触网页,想了好久才想明白应该如何进行数据的交互操作,我们可以设置参数method=["GET","POST"]。实际上我们也可以将这两部分分开,一个method="GET",另一个method="POST",有点类似于不同消息的响应。
python代码:
#设计调查问卷格式 from bottle import route, run, template, request @route('/questionnaire', method = "GET") def questionnaire(): return template('questionnaire') # login是模板名,这里不需要填写后缀.tpl @route('/questionnaire', method = "POST") def do_questionnaire(): username = request.forms.get("username") print(username) run(host='0.0.0.0', port=8080, debug=True) #开启服务
tpl代码:
<html> <head> <title>登陆页面</title> </head> <body> <p><h2>管理员登陆</h2></p> <form action="/questionnaire" method="post"> Username: <input name="username" type="text" /> Password: <input name="password" type="password" /> <br /> <input type="checkbox" name="bike" />I have a bike <br /> <input type="checkbox" name="car" />I have a car <br /> <input value="Login" type="submit" /> </form> <form action="/questionnaire" method="post"> <input type="radio" name="sex" value="male"> Male <input type="radio" name="sex" value="female"> Female </form> </body> </html>