国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

python在線編譯器的簡(jiǎn)單原理及簡(jiǎn)單實(shí)現(xiàn)代碼

2020-02-22 23:06:22
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

我們先來(lái)看一下效果(簡(jiǎn)單的寫(xiě)了一個(gè)):



原理:將post請(qǐng)求的代碼數(shù)據(jù)寫(xiě)入了服務(wù)器的一個(gè)文件,然后用服務(wù)器的python編譯器執(zhí)行返回結(jié)果

實(shí)現(xiàn)代碼:

#flaskrun.py # -*- coding: utf-8 -*- # __author__="ZJL"  from flask import Flask from flask import request from flask import Response import json import zxby  app = Flask(__name__)   def Response_headers(content):   resp = Response(content)   resp.headers['Access-Control-Allow-Origin'] = '*'   return resp  @app.route('/') def hello_world():   return Response_headers('hello world!!!')  @app.route('/run', methods=['POST']) def run():   if request.method == 'POST' and request.form['code']:     code = request.form['code']     print(code)     jsondata = zxby.main(code)     return Response_headers(str(jsondata))  @app.errorhandler(403) def page_not_found(error):   content = json.dumps({"error_code": "403"})   resp = Response_headers(content)   return resp  @app.errorhandler(404) def page_not_found(error):   content = json.dumps({"error_code": "404"})   resp = Response_headers(content)   return resp  @app.errorhandler(400) def page_not_found(error):   content = json.dumps({"error_code": "400"})   resp = Response_headers(content)   return resp  @app.errorhandler(405) def page_not_found(error):   content = json.dumps({"error_code": "405"})   resp = Response_headers(content)   return resp  @app.errorhandler(410) def page_not_found(error):   content = json.dumps({"error_code": "410"})   resp = Response_headers(content)   return resp  @app.errorhandler(500) def page_not_found(error):   content = json.dumps({"error_code": "500"})   resp = Response_headers(content)   return resp  if __name__ == '__main__':   app.run(debug=True)             
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 奉贤区| 汉中市| 淅川县| 南江县| 宜宾市| 宾川县| 江门市| 平潭县| 台东县| 虹口区| 年辖:市辖区| 荣昌县| 镇赉县| 松江区| 顺义区| 故城县| 新闻| 瓮安县| 兴海县| 新邵县| 五大连池市| 荔浦县| 泰宁县| 慈利县| 白玉县| 石林| 汝城县| 禹城市| 五指山市| 曲松县| 含山县| 怀宁县| 库车县| 临城县| 沽源县| 云南省| 安徽省| 南溪县| 唐河县| 同德县| 德江县|