本文整理汇总了Python中flask_cors.cross_origin方法的典型用法代码示例。如果您正苦于以下问题:Python flask_cors.cross_origin方法的具体用法?Python flask_cors.cross_origin怎么用?Python flask_cors.cross_origin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_cors
的用法示例。
在下文中一共展示了flask_cors.cross_origin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cors
# 需要导入模块: import flask_cors [as 别名]
# 或者: from flask_cors import cross_origin [as 别名]
def cors(cls, fn):
"""
CORS decorator, to make the endpoint available for CORS
Make sure @cors decorator is placed at the top position.
All response decorators must be placed below.
It's because it requires a response to be available
class Index(Assembly):
def index(self):
return self.render()
@request.cors
@response.json
def json(self):
return {}
:return:
"""
if inspect.isclass(fn):
raise Error("@cors can only be applied on Assembly methods")
else:
cors_fn = flask_cors.cross_origin(automatic_options=True)
return cors_fn(fn)
示例2: main
# 需要导入模块: import flask_cors [as 别名]
# 或者: from flask_cors import cross_origin [as 别名]
def main():
parser = argparse.ArgumentParser(description='Meta Reverse Image Search API')
parser.add_argument('-p', '--port', type=int, default=5000, help='port number')
parser.add_argument('-d','--debug', action='store_true', help='enable debug mode')
parser.add_argument('-c','--cors', action='store_true', default=False, help="enable cross-origin requests")
parser.add_argument('-a', '--host', type=str, default='0.0.0.0', help="sets the address to serve on")
args = parser.parse_args()
if args.debug:
app.debug = True
if args.cors:
CORS(app, resources=r'/search/*')
app.config['CORS_HEADERS'] = 'Content-Type'
global search
search = cross_origin(search)
print(" * Running with CORS enabled")
app.run(host=args.host, port=args.port)
示例3: setup_openid_metadata
# 需要导入模块: import flask_cors [as 别名]
# 或者: from flask_cors import cross_origin [as 别名]
def setup_openid_metadata(app):
@app.route("/.well-known/openid-configuration")
@cross_origin()
def openid_config():
res = {
"issuer": URL,
"authorization_endpoint": URL + "/oauth2/authorize",
"token_endpoint": URL + "/oauth2/token",
"userinfo_endpoint": URL + "/oauth2/userinfo",
"jwks_uri": URL + "/jwks",
"response_types_supported": [
"code",
"token",
"id_token",
"id_token token",
"id_token code",
],
"subject_types_supported": ["public"],
"id_token_signing_alg_values_supported": ["RS256"],
# todo: add introspection and revocation endpoints
# "introspection_endpoint": URL + "/oauth2/token/introspection",
# "revocation_endpoint": URL + "/oauth2/token/revocation",
}
return jsonify(res)
@app.route("/jwks")
@cross_origin()
def jwks():
res = {"keys": [get_jwk_key()]}
return jsonify(res)
示例4: server
# 需要导入模块: import flask_cors [as 别名]
# 或者: from flask_cors import cross_origin [as 别名]
def server(pipeline_res, host, port, debug=True):
app = Flask(__name__)
CORS(app)
# @app.route('/', methods=['GET'])
# @app.route('/index.html', methods=['GET'])
# def root():
# print("got to root")
# return app.send_static_file('static/index.html')
@app.route('/graphs', methods=['GET'])
@cross_origin()
def graphs():
# data = [d.graph.as_rdf() for d in pipeline_res["pre-process"]["train"].data]
data = [d.graph.as_rdf() for d in pipeline_res["test-corpus"].data]
return jsonify(data)
@app.route('/plans/<type>', methods=['POST'])
@cross_origin()
def plans(type):
triplets = request.get_json(force=True)
graph = Graph(triplets)
planner = pipeline_res["train-planner"]
plans = [l.replace(" ", " ")
for l in (graph.exhaustive_plan() if type == "full" else graph.plan_all()).linearizations()]
scores = planner.scores([(graph, p) for p in plans])
return jsonify({
"concat": {n: concat_entity(n) for n in graph.nodes},
"linearizations": list(sorted([{"l": l, "s": s}
for l, s in zip(plans, scores)], key=lambda p: p["s"], reverse=True))
})
@app.route('/translate', methods=['POST'])
@cross_origin()
def translate():
req = request.get_json(force=True)
model = pipeline_res["train-model"]
return jsonify(model.translate(req["plans"], req["opts"]))
@app.route('/', defaults={"filename": "index.html"})
@app.route('/main.js', defaults={"filename": "main.js"})
@app.route('/style.css', defaults={"filename": "style.css"})
def serve_static(filename):
print("Serving static", filename, os.path.join(base_path, 'static'), filename)
return send_from_directory(os.path.join(base_path, 'static'), filename)
app.run(debug=debug, host=host, port=port, use_reloader=False, threaded=True)