2013-03-22 90 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

相关问题