Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟

Posted 鏈哄櫒瀛︿範AI绠楁硶宸ョ▼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟相关的知识,希望对你有一定的参考价值。


鍚慉I杞瀷鐨勭▼搴忓憳閮藉叧娉ㄤ簡杩欎釜鍙?/span>馃憞馃憞馃憞



妯″瀷閮ㄧ讲鍜屾湇鍔¤皟鐢?/span>


瀵逛簬鍋氱畻娉曠殑鍚屽锛屽ぇ瀹舵垨澶氭垨灏戠殑鏇村叧蹇冩ā鍨嬬殑鎬ц兘鎸囨爣澶氫簺锛屽浜庝竴浜涘伐绋嬫€ч棶棰樿€冭檻鐨勮緝灏戙€傛ā鍨嬬殑閮ㄧ讲鏄繖浜涘伐绋嬫€ч棶棰樹腑閲嶈鐨勪竴涓紝瀹冪洿鎺ュ叧绯诲埌妯″瀷鍦ㄧ敓浜х郴缁熺殑浣跨敤銆備竴浜涙垚鐔熺殑鏈哄櫒瀛︿範妗嗘灦浼氭彁渚涜嚜宸辩殑瑙e喅鏂规锛屼緥濡?Tensorflow 鎻愪緵鐨?Serving 鏈嶅姟绛夈€備絾寰堝鎯呭喌涓嬫垜浠瀯寤虹殑宸ョ▼鍙兘涓嶅彧浣跨敤浜嗕竴绉嶆鏋讹紝鍥犳涓€涓鏋惰嚜韬殑閮ㄧ讲宸ュ叿鍙兘灏卞緢闅炬弧瓒虫垜浠殑闇€姹備簡銆?/p>

閽堝姝ょ被鎯呭喌锛屾湰鏂囦粙缁嶄竴涓?nbsp;绠€鍗?/strong> 鐨?nbsp;鍑嗙敓浜?/strong> 妯″瀷閮ㄧ讲鏂规銆傜畝鍗曟槸鎸囬櫎浜嗘ā鍨嬬浉鍏充唬鐮佷箣澶栫殑宸ョ▼鎬т唬鐮侀噺涓嶅ぇ锛岃繖寰楃泭浜庡皢瑕佷娇鐢ㄧ殑 Flask 妗嗘灦銆傚噯鐢熶骇鏄寚杩欑閮ㄧ讲鏂规搴斿涓€鑸殑鐢熶骇鐜闂涓嶅ぇ锛屽浜庨珮骞跺彂鐨勫満鏅彲浠ラ€氳繃妯悜鎵╁骞惰繘琛岃礋杞藉潎琛¤В鍐筹紝浣嗗浜庡崟娆¤皟鐢ㄦ椂鏁堟€ц姹傝緝楂樼殑鍦烘櫙鍒欓渶瑕佸彟瀵诲叾浠栬В鍐虫柟妗堛€?/p>



鏈枃椤圭洰浠g爜 鏂瑰紡锛?/strong>


鏈枃鏂规鐨勬ā鍨嬮儴缃插拰鏈嶅姟璋冪敤妗嗘灦濡備笅鍥炬墍绀猴細


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟



鍏朵富瑕佺壒鎬у涓嬶細

  1. 鏈嶅姟绔噰鐢?Python 鐨?Flask 妗嗘灦鏋勫缓锛屾棤闇€浣跨敤鍏朵粬澶栭儴鏈嶅姟銆侳lask 妗嗘灦鐨?nbsp;寰湇鍔?nbsp;(Microframework) 鐗规€т娇寰楁湇鍔$浠g爜绠€娲侀珮鏁堛€?/p>

  2. 鍒╃敤 Gunicorn 鎻愪緵鐨勯珮鎬ц兘 Python WSGI HTTP UNIX Server锛屾柟渚垮湪鏈嶅姟绔繍琛?Flask 搴旂敤銆?/p>

  3. 瀹㈡埛绔拰鏈嶅姟绔箣闂撮噰鐢?RESTful API 璋冪敤鏂瑰紡锛屽敖绠″湪鎬ц兘涓婂彲鑳戒笉鍙婂叾浠栦竴浜涙柟妗?(渚嬪锛氬熀浜?RPC 鐨勮В鍐虫柟妗堢瓑)锛屼絾鍏惰緝濂藉湴瑙e喅浜嗚法璇█浜や簰鐨勯棶棰橈紝涓嶅悓璇█涔嬮棿浜や簰浠呴渶浣跨敤 HTTP 鍗忚鍜?JSON 鏁版嵁鏍煎紡鍗冲彲銆?/p>


Flask 鏈嶅姟鍜?AJAX 璋冪敤

Flask 鏈嶅姟灏佽

涓轰簡灏嗘ā鍨嬩唬鐮佸拰 Flask 鏈嶅姟杩涜鏁村悎锛岄鍏堝亣璁句綘宸茬粡瀵规ā鍨嬮儴鍒嗕唬鐮佸仛浜嗗畬缇庣殑灏佽 馃暥锛屾暣涓伐绋嬪厛鍙仛 model-serving-demo 鍚с€傛暣鐞嗕竴涓嬩唬鐮佺殑鐩綍缁撴瀯锛岀粰涓€涓垜涓剰鐨?Python 鐩綍缁撴瀯椋庢牸锛?/p>


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


鎴戜滑鍒╃敤涓€涓瀬绠€鐨勭ず渚嬩粙缁嶆暣涓ā鍨嬮儴缃诧紝鐩稿叧鐨勫簱渚濊禆 requirements.txt 濡備笅锛?/span>


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


鍏朵腑锛?/p>

  1. Flask 鐢ㄤ簬鏋勫缓 Flask 鏈嶅姟銆?/p>

  2. Flask-RESTful 鐢ㄤ簬鏋勫缓 Flask RESTful API銆?/p>

  3. Flask-Cors 鐢ㄤ簬瑙e喅 AJAX 璋冪敤鏃剁殑 璺ㄥ煙闂銆?/p>

  4. jsonschema 鐢ㄤ簬瀵硅姹傛暟鎹殑 JSON 鏍煎紡杩涜鏍¢獙銆?/p>

  5. docopt 鐢ㄤ簬浠庝唬鐮佹枃妗h嚜鍔ㄧ敓鎴愬懡浠よ鍙傛暟瑙f瀽鍣ㄣ€?/p>

  6. gunicorn 鐢ㄤ簬鎻愪緵鐨勯珮鎬ц兘 Python WSGI HTTP UNIX Server銆?/p>


XXX Model 鐨勪唬鐮?nbsp;xxx_model.py 濡備笅锛?/p>


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


鍏朵腑 hello() 涓烘湇鍔′娇鐢ㄧ殑鏂规硶锛屽叾鎺ュ彈涓€涓被鍨嬩负 str 鐨勫弬鏁?nbsp;name锛屽苟杩斿洖涓€涓被鍨嬩负 str 鐨勭粨鏋溿€?/p>


XXX Model 鐨?Flask RESTful Resource 浠g爜 xxx_model_resource.py 濡備笅锛?/p>


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


鎴戜滑闇€瑕佷粠 Flask RESTful 鐨?nbsp;Resource 绫荤户鎵夸竴涓柊鐨勭被 XXXModelResource 鐢ㄤ簬澶勭悊 XXX Model 鐨勬湇鍔¤姹傘€傚涓婃枃浠嬬粛锛屾垜浠湪鏁翠釜妯″瀷鏈嶅姟璋冪敤涓娇鐢?POST 璇锋眰鏂瑰紡鍜?JSON 鏁版嵁鏍煎紡锛屽洜姝ゆ垜浠渶瑕佸湪绫?nbsp;XXXModelResource 涓疄鐜?nbsp;post() 鏂规硶锛屽悓鏃跺浜庝紶鍏ユ暟鎹殑 JSON 鏍煎紡杩涜鏍¢獙銆?/p>


post() 鏂规硶鐢ㄤ簬澶勭悊鏁翠釜妯″瀷鐨勬湇鍔¤姹傦紝xxx_model_instance 妯″瀷瀹炰緥鍦ㄧ被 XXXModelResource 澶栭儴杩涜瀹炰緥鍖栵紝閬垮厤姣忔澶勭悊璇锋眰鏃堕兘杩涜鍒濆鍖栥€?code class="mq-59">post() 鐨勮繑鍥炵粨鏋滄棤闇€澶勭悊鎴?JSON 鏍煎紡鐨勫瓧绗︿覆锛屼粎闇€杩斿洖璇嶅吀鏁版嵁鍗冲彲锛孎lask RESTful 浼氳嚜鍔ㄥ鍏惰繘琛岃浆鎹€?/p>


涓轰簡鏂逛究瀵硅姹傛暟鎹殑 JSON 鏍煎紡杩涜鏍¢獙锛屾垜浠皢瀵?JSON 鏍煎紡鐨勬牎楠屽皝瑁呮垚涓€涓慨楗板櫒銆備娇鐢ㄦ椂濡備笂鏂囦唬鐮佷腑鎵€绀猴紝鍦?nbsp;post() 鏂规硶涓婃柟娣诲姞 @validate_json(xxx_model_schema) 鍗冲彲锛屽叾涓?nbsp;xxx_model_schema 涓轰竴涓鍚?jsonschema 瑕佹眰鐨?JSON Schema銆傜ず渚嬩唬鐮佷腑瑕佹眰浼犲叆鐨?JSON 鏁版嵁 蹇呴』 鍖呭惈涓€涓悕涓?nbsp;name 绫诲瀷涓?nbsp;string 鐨勫瓧娈点€?/p>


validate_json 淇グ鍣ㄧ殑浠g爜 validation_utils.py 濡備笅锛?/p>


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟



棣栧厛鎴戜滑闇€瑕侀獙璇佽姹傚寘鍚竴涓?JSON 璇锋眰浣擄紝鍚屾椂 JSON 璇锋眰浣撶殑鍐呭闇€婊¤冻 schema 鐨勮姹傘€傚鏋滀笉婊¤冻杩欎簺鏉′欢锛屾垜浠渶瑕佽繑鍥炲搴旂殑閿欒淇℃伅 message锛屽悓鏃惰繑鍥炲悎鐞嗙殑 HTTP 鐘舵€佺爜 (渚嬪锛?code class="mq-77">400) 鐢ㄤ簬琛ㄧず鏃犳硶澶勭悊閿欒鐨勮姹傘€傚浜庢甯哥殑璇锋眰鍝嶅簲 (鍗?HTTP 鐘舵€佺爜涓?200 鐨勬儏鍐?锛岀姸鎬佺爜鍙互鐪佺暐涓嶅啓銆?/p>


鏋勫缓瀹?XXX Model 鐨?Flask RESTful Resource 鍚庯紝鎴戜滑灏卞彲浠ユ瀯寤?Flask 鐨勪富鏈嶅姟浜嗭紝涓荤▼搴忎唬鐮?nbsp;main.py 濡備笅锛?/p>


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟



docopt 搴撶敤浜庝粠浠g爜鏂囨。鑷姩鐢熸垚鍛戒护琛屽弬鏁拌В鏋愬櫒锛屽叿浣撲娇鐢ㄦ柟娉曡鍙傝 瀹樻柟鏂囨。銆傛暣涓?Flask 涓绘湇鍔$殑鏋勫缓姣旇緝绠€鍗曪紝娴佺▼濡備笅锛?/p>

  1. 鏋勫缓 Flask 涓荤▼搴忥紝app = Flask(__name__)銆?/p>

  2. 瑙e喅 AJAX 璋冪敤鐨勮法鍩熼棶棰橈紝 CORS(app)銆備负浜嗘柟渚胯捣瑙侊紝鎴戜滑涓嶅姞浠讳綍鍙傛暟锛屽厑璁镐换鎰忔潵婧愮殑璇锋眰锛岃缁嗙殑浣跨敤鏂瑰紡璇峰弬瑙?nbsp;瀹樻柟鏂囨。銆?/p>

  3. 鏋勫缓 Flask RESTful API锛?code class="mq-88">api = Api(app)銆?/p>

  4. 灏嗘瀯寤哄ソ鐨?XXX Model 鐨?Flask RESTful Resource 娣诲姞鍒?API 涓紝api.add_resource(XXXModelResource, '/v1/XXXModel')銆傚叾涓浜屼釜鍙傛暟涓鸿姹傜殑 URL锛屽浜庤繖涓?URL 鐨勫缓璁皢鍦ㄥ悗缁皬鑺備腑璇︾粏璇存槑銆?/p>


Flask 涓荤▼搴忛厤缃畬姣曞悗锛屾垜浠€氳繃 app.run() 鍦ㄦ湰鍦板惎鍔?Flask 鏈嶅姟锛屽悓鏃跺彲浠ユ寚瀹氱粦瀹氱殑涓绘満鍚嶏紝绔彛锛屼互鍙婃槸鍚﹀紑鍚皟璇曟ā寮忕瓑銆傞€氳繃 python main.py 鍚姩 Flask 鏈嶅姟鍚庯紝鍙互鍦ㄥ懡浠よ鐪嬪埌濡備笅绫讳技鐨勬棩蹇楋細


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟



鐜板湪灏卞彲浠ユ祴璇曡皟鐢ㄦ湇鍔′簡锛屾垜浠敤 curl 鍛戒护杩涜绠€鍗曠殑娴嬭瘯锛岀浉鍏充唬鐮?nbsp;request-demo.sh 濡備笅锛?/span>


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


涓夌涓嶅悓鐨勮姹傝繑鍥炵殑 HTTP 鐘舵€佺爜鍜岀粨鏋滃涓嬶細


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


涓婃枃涓紝鎴戜滑閫氳繃 python main.py 鍒╃敤鍐呯疆鐨?Server 鍚姩浜?Flask 鏈嶅姟锛屽惎鍔ㄥ悗鏃ュ織涓墦鍗板嚭鏉ヤ竴鏉¤鍛婁俊鎭紝鍛婅瘔浣跨敤鑰呬笉瑕佸湪鐢熶骇鐜涓娇鐢ㄥ唴缃殑 Server銆傚湪鐢熶骇鐜涓垜浠彲浠ュ埄鐢ㄩ珮鎬ц兘 Python WSGI HTTP UNIX Server gunicorn 鏉ュ惎鍔?Flask 鏈嶅姟銆?/p>


鏈嶅姟鍚姩 (start.sh) 鑴氭湰浠g爜濡備笅锛?/p>


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


鏈嶅姟鍋滄 (stop.sh) 鑴氭湰浠g爜濡備笅锛?/span>


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


gunicorn 鐨勮缁嗗弬鏁伴厤缃拰浣跨敤鏁欑▼璇峰弬瑙?nbsp;瀹樻柟鏂囨。銆?/span>

https://docs.gunicorn.org/en/stable/


RESTful API 璁捐

RESTful API 鏄竴绉嶇鍚?REST (Representational State Transfer锛岃〃鐜板眰鐘舵€佽浆鎹? 鍘熷垯鐨勬鏋讹紝璇ユ鏋舵槸鐢?Fielding 鍦ㄥ叾鍗氬+璁烘枃 1 涓彁鍑恒€傜浉鍏崇殑鏍稿績姒傚康濡備笅锛?/p>

  1. 璧勬簮 (Resources)锛屽嵆缃戠粶涓殑涓€涓疄浣?(鏂囨湰锛屽浘鐗囷紝鏈嶅姟绛?锛屼娇鐢ㄤ竴涓?URL 杩涜琛ㄧず銆?/p>

  2. 琛ㄧ幇灞?(Representation)锛岃祫婧愬叿浣撶殑鍛堢幇褰㈠紡鍗充负琛ㄧ幇灞傦紝渚嬪鍥剧墖鍙互琛ㄧず涓?PNG 鏂囦欢锛岄煶涔愬彲浠ヨ〃绀轰负 MP3 鏂囦欢锛岃繕鏈夋湰鏂囦娇鐢ㄧ殑鏁版嵁鏍煎紡 JSON 绛夈€侶TTP 璇锋眰鐨勫ご淇℃伅涓敤 Accept 鍜?Content-Type 瀛楁瀵硅〃鐜板眰杩涜鎻忚堪銆?/p>

  3. 鐘舵€佽浆鎹?(State Transfer)锛屼簰鑱旂綉閫氫俊鍗忚 HTTP 鍗忚鏄竴涓棤鐘舵€佸崗璁紝鎵€鏈夌殑鐘舵€侀兘淇濆瓨鍦ㄦ湇鍔$銆傚洜姝ゅ鏋滃鎴风鎯宠鎿嶄綔鏈嶅姟鍣紝蹇呴』閫氳繃鏌愮鎵嬫璁╂湇鍔″櫒绔彂鐢?nbsp;鐘舵€佽浆鎹?/strong>銆傚鎴风鍒╃敤 HTTP 鍗忚涓殑鍔ㄤ綔瀵规湇鍔″櫒杩涜鎿嶄綔锛屼緥濡傦細GET锛孭OST锛孭UT锛孌ELETE 绛夈€?/p>

鍒╃敤 RESTful API 鏋勫缓妯″瀷鏈嶅姟鏃讹紝闇€瑕佹敞鎰忓涓嬪嚑鐐癸細

  1. 涓烘ā鍨嬫湇鍔¤缃笓鐢ㄥ煙鍚嶏紝渚嬪锛?code class="mq-130">https://api.example.com锛屽苟閰嶄互璐熻浇鍧囪 銆?/p>

  2. 灏?API 鐨勭増鏈彿鍐欏叆 URL 涓紝渚嬪锛?code class="mq-131">https://api.example.com/v1銆?/p>

  3. RESTful 妗嗘灦涓瘡涓?URL 琛ㄧず涓€绉嶈祫婧愶紝鍥犳鍙互灏嗘ā鍨嬬殑鍚嶇О浣滀负 URL 鐨勭粓鐐?(Endpoint)锛屼緥濡傦細

  4. https://api.example.com/v1/XXXModel銆?/p>

  5. 瀵逛簬鎿嶄綔璧勬簮鐨?HTTP 鏂瑰紡鏈夊绉嶏紝缁煎悎鑰冭檻寤鸿閫夌敤 POST 鏂瑰紡锛屽悓鏃跺缓璁娇鐢?JSON 鏁版嵁鏍煎紡銆?/p>

  6. 涓鸿姹傚搷搴旇缃悎鐞嗙殑鐘舵€佺爜锛屼緥濡傦細200 OK 琛ㄧず姝e父杩斿洖锛?00 INVALID REQUEST 琛ㄧず鏃犳硶澶勭悊瀹㈡埛绔殑閿欒璇锋眰绛夈€?/p>

  7. 瀵逛簬閿欒鐮佷负 4xx 鐨勬儏鍐碉紝寤鸿鍦ㄨ繑鍥炰腑娣诲姞閿悕涓?nbsp;message 鐨勯敊璇俊鎭€?/p>


AJAX 璋冪敤

瀵逛簬鍔ㄦ€佺綉椤碉紝鎴戜滑鍙互寰堝鏄撶殑鍦ㄥ悗绔湇鍔′腑鍙戣捣 POST 璇锋眰璋冪敤妯″瀷鏈嶅姟锛岀劧鍚庡皢缁撴灉鍦ㄥ墠绔繘琛屾覆鏌撱€傚浜庨潤鎬佺綉椤碉紝鎴戜滑鍙互鍒╃敤 AJAX 杩涜鐩稿叧鎿嶄綔銆傞鍏堟垜浠渶瑕佷竴涓氦浜掔晫闈紝濡備笅涓哄埄鐢?Google Material Design 椋庢牸鐨?Material Design Components Web 缁勪欢璁捐涓€涓氦浜掔晫闈紝瀹炵幇缁嗚妭璇峰弬瑙?nbsp;绀轰緥浠g爜銆?/p>

https://github.com/leovan/model-serving-demo/tree/master/client/xxx-model-ajax-client.html


AJAX 鏈嶅姟璇锋眰浠g爜鐨勬牳蹇冮儴鍒嗗涓嬶細


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


浠g爜浣跨敤浜?nbsp;jQuery 鐨勭浉鍏冲嚱鏁般€?/span>JSON.stringify({"name": $("#name").val()}) 鑾峰彇 ID 涓?nbsp;name 鐨勫厓绱犵殑鍊硷紝骞跺皢鍏惰浆鎹㈡垚绗﹀悎鏈嶅姟绔姹傜殑 JSON 鏍煎紡銆傞€氳繃 AJAX 鍚戣繙绋嬪彂鍑鸿姹傚悗锛屽鏋滆姹傛垚鍔熷垯灏嗚繑鍥炴暟鎹?nbsp;data 涓搴旂殑缁撴灉 result 濉厖鍒?ID 涓?nbsp;result 鐨勫厓绱犱腑锛屽惁鍒欏~鍏ヨ繑鍥炵殑閿欒淇℃伅銆?/span>


Google App Engine 閮ㄧ讲

涓婃枃涓凡缁忎粙缁嶄簡濡備綍鍦ㄦ湰鍦板埄鐢?Flask 閮ㄧ讲妯″瀷鏈嶅姟鍜岀浉鍏宠皟鐢ㄦ柟娉曪紝浣嗗鏋滃笇鏈涘湪鑷繁鐨勭綉绔欎腑璋冪敤鏃讹紝鍒欏埄鐢?SaaS 鏉ラ儴缃茬鍚堜細鏄竴涓笉浜屼箣閫夈€傚浗鍐呭澶氫釜鍘傚晢鍧囨彁渚涗簡鐩稿簲鐨?SaaS 浜у搧锛屼緥濡?Google锛孉mazon锛孧icrosoft 绛夈€侴oogle App Engine (GAE) 鎻愪緵浜嗕竴涓?nbsp;濮嬬粓鍏嶈垂 鏂规锛岃櫧鐒堕儴缃查樁娈典細鍙楀埌 GFW 鐨勫奖鍝嶏紝浣嗚皟鐢ㄩ樁娈垫祴璇曞奖鍝嶅苟涓嶆槸寰堝ぇ (涓嶅悓鍦板尯鍜屾湇鍔℃彁渚涘晢浼氭湁宸紓)銆傜患鍚堣€冭檻锛屾湰鏂囬€夋嫨 GAE 浣滀负 SaaS 骞冲彴閮ㄧ讲鏈嶅姟锛屽悇浣嶇湅瀹樿鑷姊瓙銆?/p>

鐜鍑嗗

棣栧厛锛屽湪 Google Cloud Platform Console 涓缓绔嬩竴涓柊鐨?Project锛屽亣璁鹃」鐩悕涓?nbsp;YOUR_PROJECT_ID銆?/p>


鍏舵锛屾牴鎹?Google Cloud SDK 鏂囨。 鍦ㄦ湰鍦板畨瑁呯浉搴旂増鏈殑 Google Cloud SDK銆侻acOS 涓嬪缓璁€氳繃 brew cask install google-cloud-sdk 鏂瑰紡瀹夎锛屽畨瑁呭畬姣曞悗纭鍦ㄥ懡浠よ涓彲浠ヨ繍琛?nbsp;gcloud 鍛戒护銆?/p>


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


鏋勫缓 GAE 宸ョ▼

妯″瀷鏈嶅姟浠呬綔涓哄悗绔簲鐢紝鍥犳鏈妭涓嶄粙缁嶅墠绔〉闈㈠紑鍙戠殑鐩稿叧閮ㄥ垎锛屾湁鍏磋叮鐨勫悓瀛﹁鍙傝 瀹樻柟鏂囨。銆侴AE 閮ㄧ讲 Python Web 搴旂敤閲囩敤浜?WSGI 鏍囧噯锛屾垜浠瀯寤虹殑鏈湴閮ㄧ讲鐗堟湰瀹屽叏婊¤冻杩欎釜瑕佹眰锛屽洜姝や粎闇€涓洪」鐩湪鏍圭洰褰曟坊鍔犱竴涓?GAE 閰嶇疆鏂囦欢 app.yaml 鍗冲彲锛屽唴瀹瑰涓嬶細


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


鍏朵腑锛?code class="mq-167">runtime 鎸囧畾浜嗘湇鍔¤繍琛岀殑鐜锛?code class="mq-168">handlers 鎸囧畾浜嗕笉鍚岀殑 URL 瀵瑰簲鐨勫鐞嗙▼搴忥紝鍦ㄦ鎵€鏈夌殑 URL 鍧囩敱 main.py 涓殑 app 杩涜澶勭悊锛?code class="mq-171">skip_files 鐢ㄤ簬杩囨护涓嶉渶瑕佷笂浼犵殑鏂囦欢銆傛洿澶氬叧浜?nbsp;app.yaml 鐨勮缃俊鎭紝璇峰弬瑙?nbsp;瀹樻柟鏂囨。銆?/p>

閮ㄧ讲 GAE 宸ョ▼

鍦ㄩ儴缃?GAE 宸ョ▼涔嬪墠鎴戜滑鍙互鍒╃敤鏈湴鐨勫紑鍙戠幆澧冨鍏惰繘琛屾祴璇曪紝娴嬭瘯鏃犺鍚庯紝鍗冲彲杩愯濡備笅鍛戒护灏嗗叾閮ㄧ讲鍒?GAE 涓婏細


Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟


鐒跺悗鏍规嵁鍛戒护琛屾彁绀哄畬鎴愭暣涓儴缃叉祦绋嬶紝閮ㄧ讲瀹屾垚鐨勮繙绋嬫湇鍔?URL 涓?nbsp;https://YOUR_PROJECT_ID.appspot.com锛屾洿澶氱殑娴嬭瘯鍜岄儴缃茬粏鑺傝鍙傝 瀹樻柟鏂囨。銆?/p>


閮ㄧ讲鍚庣殑 GAE 鏈嶅姟浣跨敤浜嗗叾鑷甫鐨勫煙鍚?nbsp;appspot.com銆傚鏋滀綘鎷ユ湁鑷繁鐨勫煙鍚嶏紝鍙互鏍规嵁瀹樻柟鏂囨。 璁剧疆鑷繁鐨勫煙鍚?nbsp;骞?nbsp;寮€鍚?SSL銆?/p>





闃呰杩囨湰鏂囩殑浜鸿繕鐪嬩簡浠ヤ笅鏂囩珷锛?/strong>






























































涓嶆柇鏇存柊璧勬簮

娣卞害瀛︿範銆佹満鍣ㄥ涔犮€佹暟鎹垎鏋愩€乸ython

Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟



鏈哄櫒瀛︿範绠楁硶璧勬簮绀剧兢

涓嶆柇涓婁紶鐢靛瓙鐗圥DF璧勬枡

鎶€鏈棶棰樻眰瑙?br class="mq-333">

Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟








AI椤圭洰浣撻獙

https://loveai.tech


以上是关于Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟的主要内容,如果未能解决你的问题,请参考以下文章

在 Flask + Google App Engine 上启用 SSL

Google App Engine / Datastore / Flask / Python app 中的内存泄漏

Python Flask:从 Swagger YAML 到 Google App Engine?

与 Google App Engine 和 Flask 一起使用时,Angular 路由不起作用

在 Google App Engine 上运行 Alembic 迁移

如果Flask应用程序在Google App Engine中不可用,如何提供默认错误页面