2012-02-21 28 views
0

我正在嘗試使用Google App Engine製作一個簡單的應用程序。配置腳本處理程序Google App Engine

下面是我的代碼

helloworld.py

print "hello" 

class helloworld(): 
     def myfunc(self): 
       st = "inside class" 
       return st 

test.py

import helloworld 

hw_object = helloworld.helloworld() 
print hw_object.myfunc() 

app.yaml

handlers: 
- url: /.* 
    script: helloworld.py 

- url: /.* 
    script: test.py 

當我るñ我的申請通過http://localhost:10000它只打印hello而我的預期輸出是helloinside class

我的目錄結構

E:\helloworld>dir 
app.yaml  helloworld.py test.py 

我敢肯定這事做與Script Handlers。所以,什麼是定義處理的,什麼是錯誤的,我定義它們的方式的正確方法。

+0

你的意思是有兩個相同的路徑正則表達式? – bernie 2012-02-21 05:54:05

+0

我的意思是,如果我的文件夾中有多個腳本,我該如何配置我的'app.yaml'。我試過上述模式,它沒有工作。我需要的是如果我運行'localhost:10000'我的腳本應該是執行,但沒有發生。 – RanRag 2012-02-21 05:55:27

+0

@AdamBernier:我想'網址:/測試/.*'但仍沒有運氣。 – RanRag 2012-02-21 06:10:22

回答

3

當您的第一個處理程序模式/.*匹配http://localhost:10000時,其餘處理程序全部被忽略。

您可以更新您的app.yaml

handlers: 
- url: /hello 
    script: helloworld.py 

- url: /test 
    script: test.py 

和瀏覽http://localhost:10000/test

0

請從appengine文檔中查看入門指南。它可以幫助你解決像這樣的初始設置問題。

http://code.google.com/appengine/docs/python/gettingstarted/helloworld.html

下面是從文檔的樣品處理程序。

from google.appengine.ext import webapp 
from google.appengine.ext.webapp.util import run_wsgi_app 

class MainPage(webapp.RequestHandler): 
    def get(self): 
     self.response.headers['Content-Type'] = 'text/plain' 
     self.response.out.write('Hello, webapp World!') 

application = webapp.WSGIApplication(
           [('/', MainPage)], 
           debug=True) 

def main(): 
    run_wsgi_app(application) 

if __name__ == "__main__": 
    main() 

注意該類擴展webapp.RequestHandler,方法名是獲得(或後,如果您是在響應HTTP POST請求)還是在底部設置應用程序的額外的代碼。您可以通過向WSGIApplication添加參數來爲應用程序添加額外的URL。例如:

application = webapp.WSGIApplication(
           [('/', MainPage)], 
           [('/help/', HelpPage)], 
           debug=True) 

另外請注意,在你的app.yaml作爲兩個腳本指向同一個URL模式,也沒有辦法,任何要求都不會得到test.py.正常模式是在頂部具有特定的網址模式,最後是全部模式。

祝你好運。

0

我也有類似的問題太多。擴大對哈米什的回答,並糾正其中的方括號是最後一部分:

application = webapp.WSGIApplication([ 
          ('/', MainPage), 
          ('/help/', HelpPage)], 
          debug=True) 

參考: https://webapp-improved.appspot.com/guide/routing.html

**編輯我也有一個額外的右括號在我上面的代碼。現在改變了。

相關問題