首页 > 其他 > 详细

Flask 基础

时间:2019-12-05 13:37:04      阅读:90      评论:0      收藏:0      [点我收藏+]

?

Flask 中的 Response

  1. #?-*-?coding:?utf-8?-*-??
  2. from?flask?import?Flask,?redirect,?render_template,?jsonify,?send_file??
  3. ?? ?
  4. app?=?Flask(__name__)??
  5. ?? ?
  6. ?? ?
  7. @app.route(‘/‘)??
  8. def?index():??
  9. ????return?redirect(‘/login‘)??#?跳转,重定向??
  10. ?? ?
  11. ?? ?
  12. @app.route(‘/login‘)??
  13. def?login():??
  14. ????return?render_template(‘login.html‘)??#?返回模板有浏览器渲染??
  15. ?? ?
  16. ?? ?
  17. @app.route(‘/json‘)??
  18. def?json():??
  19. ????data?=?{??
  20. ????????"name":?‘peach‘??
  21. ????}??
  22. ????return?jsonify(data)??#?返回json标准字符串??
  23. ?? ?
  24. ?? ?
  25. @app.route(‘/send_files‘)??
  26. def?send_files():??
  27. ????return?send_file(‘Dockerfile‘)??#?返回文件(打开文件,并返回文件内容,自动识别)??
  28. ?? ?
  29. ?? ?
  30. app.run(host=‘0.0.0.0‘,?debug=True)??

?

技术分享图片

Flask 基础

原文:https://www.cnblogs.com/py-web/p/11988296.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!