Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use python http Services flask Architecture

Shulou Source: shulou.com Published: 2022-06-02 22:35:38 10月02日 Update

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!

Tags: Architecture service content method more knowledge result Douban practical learned next code dilemma entity reality situation article spring breeze standard case Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB MySQL Apple Xiaomi Huawei