国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 鄂州市| 道孚县| 扎赉特旗| 白玉县| 浙江省| 林周县| 新竹县| 莱州市| 文山县| 广州市| 申扎县| 大埔县| 抚远县| 高清| 遂宁市| 茌平县| 桐庐县| 赤水市| 北票市| 漳州市| 宁南县| 临江市| 七台河市| 镇安县| 大关县| 靖江市| 墨竹工卡县| 大化| 繁峙县| 渭南市| 灵宝市| 铜川市| 招远市| 玛纳斯县| 乌兰浩特市| 渝北区| 虎林市| 虎林市| 陵水| 东源县| 肇东市|