2013-05-02 35 views
1

我想在加载时解析URL以查看它是否有任何参数。我只是试图建立一个基本的测试,看看是否有可能。什么是正确的正则表达式发送像http://example.com/?hiyall的网址给ParamHandler?检测URL是否包含GAE中的参数

class ParamHandler(webapp2.RequestHandler): 
    def get(self): 
     self.response.out.write('parameters detected') 


class MainHandler(webapp2.RequestHandler): 
    def get(self): 
     self.response.out.write('Hello World') 



application = webapp2.WSGIApplication ([('/', MainHandler), ('/\?.*', ParamHandler)], debug=True) 
+1

你的意思是所有以hiyall结尾(例如phiyall)或类似http://example.com/?hiyall=somevalue一些GET参数的要求。 – specialscope 2013-05-02 03:29:11

+0

我的意思是任何涉及“example.com/?”的东西。我想我知道如何解析url,但是现在我需要知道如何在有参数的情况下获取URL。 – jumbopap 2013-05-02 03:30:57

+0

可能与以下内容有关:http://stackoverflow.com/a/7168126/1988505 – 2013-05-02 03:34:35

回答

0

如果您使用webapp2的,你不能基于参数路由请求。

但您可以根据query_string创建一个条件,它可以检查参数是否存在。像下面这样:

class MainHandler(webapp2.RequestHandler): 
    def get(self): 
     if self.request.query_string: 
      self.response.out.write('Has parameters') 
     else: 
      self.response.out.write('No parameters') 



application = webapp2.WSGIApplication ([('/', MainHandler)], debug=True) 
相关问题