python flask post parameters

python flask post parameters

# https://blog.csdn.net/sinat_38682860/article/details/82354342###
from flask import Flask, request
from flask_cors import cross_origin

app=Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route('/aa')
def hello_aa():
    return 'Hello aa!'

@app.route('/post1',methods=['POST'])
@cross_origin()
def postTest():
    name = request.form.get('name')
    return name;


if __name__=='__main__':
    app.run()

js call

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
    <script>
        $.post("http://127.0.0.1:5000/post1", {name:'testname'}, function (ret) {
            alert(ret)
        })
    </script>
</body>
</html>

 

Guess you like

Origin blog.csdn.net/qq503690160/article/details/112785315