当前位置:   article > 正文

Python flask request

Python flask request
  1. from flask import Flask, render_template, request
  2. app = Flask(__name__)
  3. @app.route('/index', methods=['GET', "POST"])
  4. def index():
  5. if request.method == "GET":
  6. return render_template("index.html")
  7. if request.method == "POST":
  8. return 'this is post'
  9. if __name__ == '__main__':
  10. app.run(debug=True)

第一。获取get和post请求 如代码所示

第二 获取数值

  1. from flask import Flask, render_template, request
  2. app = Flask(__name__)
  3. @app.route('/index', methods=['GET', "POST"])
  4. def index():
  5. if request.method == "GET":
  6. return render_template("index.html")
  7. if request.method == "POST":
  8. name = request.form.get("name")
  9. password = request.form.get("password")
  10. print(name, password)
  11. return 'this is post'
  12. if __name__ == '__main__':
  13. app.run(debug=True)

h5代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <form action="" method="post">
  9. 账号:
  10. <input type="text" name="name">
  11. <br>
  12. 密码:
  13. <input type="password" name="password">
  14. <br>
  15. <input type="submit" name="submit">
  16. </form>
  17. </body>
  18. </html>


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/325729
推荐阅读
相关标签
  

闽ICP备14008679号