看得懂就会领会代码奥妙。
from flask import Flask
import threading
app = Flask(__name__)
@app.route('/')
def hello_world():
return '{} age is {}'.format(FlaskParams.flask_str, FlaskParams.flask_int)
# 类似全局变量,进而传递给flask服务
class FlaskParams(object):
flask_str = 'str1'
flask_int = 10
class FlaskManager(object):
def __init__(self):
pass
def set_flask_params(self, flask_str, flask_int):
FlaskParams.flask_str = flask_str
FlaskParams.flask_int = flask_int
def run(self, ip='0.0.0.0', port=5200, debug=False):
threading.Thread(target=app.run, args=(ip, port, debug)).start()
if __name__ == '__main__':
fm = FlaskManager()
fm.run()
fm.set_flask_params('xiaoming', 29)