標籤:轉換 組合 hello mit 是你 問題 art htm lin
1、python程式部署到sae上需要做的改動
線上上需要轉換成wsgi的形式運行python程式。
sae中運行python程式需要指定一個函數為入口函數。
application = sae.create_wsgi_app(main)
main函數是你定義的入口函數,在這裡面你可以調用你定義的其它函數。
sae.create_wsgi_app(main) 建立main為入口函數,將入口地址返回給application。
運行這個程式的時候sae會直接找到application,運行這個python程式。
另外入口函數(main)必須要有兩個參數:environ 和 start_response
所以你的入口函數要這樣寫:
1 def main(environ,start_response):2 status = ‘200 OK‘3 response_headers = [(‘Content-type‘,‘text/plain‘)]4 write = start_response(status,response_headers)5 6 return [‘Hello world‘]
這裡面定義了一個返回的包,status為狀態代碼,200表示成功,response_headers為包的頭部,return返回body的內容,組合起來就是一個完整的包。
sae中運行python程式基本就要做這些改變,你的其它程式可以在main函數的基礎上擴充。另外還有sae不支援一些第三方庫的問題,這一節不贅述了。
關於程式的設定詳見官方文檔:請求處理
2、sae git 提交記住使用者名稱、密碼
詳見:使用GitBash記住在新浪Sae上Git倉庫的帳號密碼,以後再也不用輸帳號密碼啦!
3、運行 git 指令碼
調試的時候每次重複輸入幾條命令比較麻煩?試試將所有命令寫成一個小指令碼來運行!
使用方法:
git config --global alias.push1 ‘!git add . && git commit -m "update" && git push sae master:1‘
git控制台中直接運行:
git push1
就可以運行這個指令碼啦!
參考自:Git批處理指令碼
4、wsgi處理get請求
參考自:web python -- WSGI介面GET請求
WSGI介面 <==處理url路徑問題
Freecode# : www.cnblogs.com/yym2013
新浪雲SAE搭建python環境 問題拾遺