# -*- coding: UTF-8 -*- # 开发人员:萌狼蓝天 # 博客:Https://mllt.cc # 笔记:Https://cnblogs.com/mllt # 哔哩哔哩/微信公众号:萌狼蓝天 # 开发时间:2022/5/6 # Coding:UTF-8 import flask, json from flask import request import oemail from flask_cors import CORS, cross_origin # 导入包 from functools import wraps from flask import make_response from flask import render_template server = flask.Flask(__name__) # 将该py文件转为一个服务 from package_info import API_INFO server.register_blueprint(API_INFO) from dynamic_toekn import API_DyNamicToken server.register_blueprint(API_DyNamicToken) # from OpenCVTool import API_OpenCVTool # server.register_blueprint(API_OpenCVTool) CORS(server, supports_credentials=True) # 设置参数 def allow_cross_domain(fun): @wraps(fun) def wrapper_fun(*args, **kwargs): rst = make_response(fun(*args, **kwargs)) rst.headers['Access-Control-Allow-Origin'] = '*' rst.headers['Access-Control-Allow-Methods'] = 'PUT,GET,POST,DELETE,OPTIONS,*' allow_headers = "Referer,Accept,Origin,User-Agent" rst.headers['Access-Control-Allow-Headers'] = allow_headers return rst return wrapper_fun @server.route('/', methods=["GET"]) def index(): return render_template('index.html') @server.route('/doc', methods=["GET"]) def document(): return render_template('document.html') @server.route('/docs/doc', methods=["GET"]) def documentReturn(): return render_template('document.html') @server.route('/docs/qq', methods=["GET"]) def page_doc_info_qq(): return render_template('info/qq.html') @server.errorhandler(404) def page_not_found(e): return render_template('404.html'), 404 @server.errorhandler(500) def internal_server_error(e): return render_template('500.html'), 500 @server.route('/email/code', methods=['post']) @allow_cross_domain def emailSendCode(): receiver = request.values.get('receiver') name = request.values.get('name') key = request.values.get('key') # key="qq2686485465" return oemail.send(receiver, name, key) if __name__ == '__main__': server.run(debug=False, port=2312, host='0.0.0.0') # 指定端口,host,0.0.0.0代表不管几个网卡,任何ip都可访问