from flask import Flask,request,render_template_string,render_template from jinja2 import Template import json import heaven def merge(src, dst): for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
@app.route('/m4G1c',methods=['POST', 'GET']) def pollute(): if request.method == 'POST': if request.is_json: merge(json.loads(request.data), instance) result = heaven.create() message = result["message"] return "这个魔术还行吧 " + message else: return "我要json的魔术" return "记得用POST方法把魔术交上来"
#heaven.py
def create(kon="Kon", pure="Pure", *, confirm=False): if confirm and "lucky_number" not in create.__kwdefaults__: return {"message":"嗯嗯,我已经知道你要创造东西了,但是你怎么不告诉我要创造什么?","lucky_number":"nope"} if confirm and "lucky_number" in create.__kwdefaults__: return {"message":"这是你的lucky_number,请拿好,去/check下检查一下吧","lucky_number": create.__kwdefaults__["lucky_number"]}