2013-03-22 176 views
0

我需要檢索/之後的任何字符串,並在下面的GetPost類中檢索該字符串。例如:/test123,/blah等在下面的應用程序應該去GetPost類。正則表達式應用引擎

如何在下面的代碼中實現上述要求?有我需要導入的任何模塊嗎?

class GetPost(webapp2.RequestHandler): 
    def get(self): 
     self.response.write("Permalink") 

app = webapp2.WSGIApplication([ 
    ('/', HomePage), 
    ('/new-post', NewPost), 
    ('/create-post', CreatePost), 
    ('/.+', GetPost) 
    ], debug=True); 
+0

如果您要修復錯誤,請移除堆棧跟蹤。 – bossylobster 2013-03-22 04:45:00

回答

3

您只需create a capture group你想要表達的:

app = webapp2.WSGIApplication([ 
    ... 
    ('/(.+)', GetPost) 
    ... 

,幷包括一個額外的參數的GET處理程序:

class GetPost(webapp2.RequestHandler): 
    def get(self, captured_thing): 
     self.response.write(captured_thing) 

使請求/xyz將導致captured_thing被設置爲'xyz'

+0

但是我怎樣才能檢索GetPost類中的'/ permalink'值。 ? – 2013-03-22 04:47:06

+0

是的,現在一切正常。非常感謝 :) – 2013-03-22 04:51:02

相關問題