🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` import flask,json from flask import request server = flask.Flask(__name__) @server.route('/login',methods=['get','post']) @server.route('/') def login(): username = request.values.get('name') pwd = request.values.get('pwd') if username and pwd: if username == 'zhang' and pwd == '123': resu = {'code':200,'message':'登录成功','token':'1651AS'} return json.dumps(resu,ensure_ascii=False) else: resu = {'code':-1,'message':'账号密码错误'} return json.dumps(resu,ensure_ascii=False) else: resu = {'code':10001,'message':'参数不能为空1111'} return json.dumps(resu,ensure_ascii=False) def index(): resu = {'code':200,'message':'登录成功','token':'1651AS'} return json.dumps(resu,ensure_ascii=False) if __name__ == '__main__': server.run(debug=True,port=8788,host='127.0.0.1') ``` ``` from flask import Flask app = Flask(__name__) @app.route('/') def index(): return '<h1>Hello World</h1>' if __name__ == '__main__': app.run() ``` ``` import json from flask import Flask from flask import request jsonok = open("treeyuan.json",encoding="utf-8") jsonok1 =json.load(jsonok) dict1 = {} def getjson(k,j): for key in j: #print(j[key]) if(isinstance(j[key],str)): if j[key] == k: #print(j) #dict2 =j.copy() dict1.update(j) if(isinstance(j[key],list)): for i in j[key]: if(isinstance(i,dict)): getjson(k,i) app = Flask(__name__) @app.route('/') def index(): username = request.values.get('name') #print('123') if username == 'TreeMapLayout': #print('123') getjson(username,jsonok1) return json.dumps(dict1,ensure_ascii=False) else: resu = jsonok1 return json.dumps(resu,ensure_ascii=False) if __name__ == '__main__': app.run(debug=True,port=8888,host='127.0.0.1') ```