学习中心
登录
已解决
点get,请求不成功
from flask import Flask,request

app = Flask(__name__,static_url_path='/laoxiao',static_folder='static')  #初始化flask项目服务

@app.route('/')    #装饰器-路由
def hello_world():
    return 'Hello World!'

@app.route('/test1.html', methods=['GET'])
def test1():
    user_id = request.args.get('user_id')
    print("用户id是:{}".format(user_id))
    name = request.args.get('name')
    print("用户的名字是:{}".format(name))
    return "请求成功"

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=8080,debug=False)  #在企业中设置为false

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试请求方式和请求参数</title>
    <style>
        .parent{
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="parent">
        <h2>请求方式</h2>
        <a href="/test1?user_id=100&name=zhangsan">get请求</a>
        <h5>post请求</h5>
        <form action="" method="post">
            <input type="text">
            <input type="submit">
        </form>
    </div>

</body>
</html>

f4cc48ac6c3eb1ebb479cc39ef4eca9e.png

53 1
    1个回答
    你还没有查看该回答的权限哦~请先获取查看权限
    立即查看
    写回答