python 使用bottle搭建网页,如何在后台获取数据

想利用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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值