In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to use the flask architecture of python http services". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Dependent library
Flask installation, using Douban source acceleration.
Pip install flask-I https://pypi.douban.com/simple
Gevent installation, using Douban source acceleration.
Pip install gevent-I https://pypi.douban.com/simple code #! / user/bin/env python# coding=utf-8 "" @ project: TestDemo@author: huyi@file: app.py@ide: PyCharm@time: 2021-10-15 11:58:44 "" from flask import Flask, requestfrom gevent.pywsgi import WSGIServerfrom gevent import monkeyimport json # replaces the io methods of the python standard with methods of the same name in gevent Gevent automatically switches monkey.patch_all () app = Flask (_ _ name__) # request returns entity class TestResponse: def _ init__ (self, code, success, msg, data): self.code = code self.success = success self.msg = msg self.data = data @ app.route ('/ progress') Methods= ['POST']) def progress (): request_data = json.loads (request.data) print ("Progress callback: {}" .format (request_data)) return json.dumps (TestResponse (0, True, "progress callback success", None), default=lambda obj: obj.__dict__, sort_keys=True, indent=4) @ app.route (' / result') Methods= ['POST']) def result (): request_data = json.loads (request.data) print ("result callback: {}" .format (request_data)) return json.dumps (TestResponse (0, True, "result callback success", None), default=lambda obj: obj.__dict__, sort_keys=True, indent=4) if _ _ name__ = =' _ main__': print Ask about the spring breeze. ") WSGIServer (('0.0.0.0, 8383), app) .serve_forever ()
Validate the results using postman
That's all for "how to use python http Services flask Architecture". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 301
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.