Flask接收GET,POST数据

from flask import *

app=Flask(__name__)
@app.route("/",methods=["get","POST"])#默认为GET方式,需要添加POST方式,不然会报405错误
def index():
    if request.method == 'GET':#判断是否为GET方式
        args = request.args    #获取get中的数据
        return "hello,"+args.get('name')+"<br>this is get!"
    if request.method == 'POST':#判断是否为POST方式
        return "hello "+"<br>this is post"
if __name__ == '__main__':
    app.run()

html代码

<html>
<head>
	<title>test</title>
</head>
<body>
<form action="http://127.0.0.1:5000/" method="post">
<input type="text" name="name">
<input type="submit">
</form>
</body>
</html>
posted @ 2017-04-27 14:22  Makki  阅读(588)  评论(0编辑  收藏  举报