1

I would like to parse the URL upon load to see if it has any parameters. I'm just trying to set up a basic test to see if that's possible. What is the correct regex to send a url like http://example.com/?hiyall to ParamHandler?

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)
jumbopap
  • 3,969
  • 5
  • 27
  • 47
  • 1
    Do you mean all the requests that end with hiyall (eg. phiyall) or some get parameter like http://example.com/?hiyall=somevalue. – specialscope May 02 '13 at 03:29
  • I mean anything involving "example.com/?". I think I know how to parse the url but right now I need to know how to get a hold of the url when it has parameters. – jumbopap May 02 '13 at 03:30
  • Possibly related to: http://stackoverflow.com/a/7168126/1988505 – Wesley Baugh May 02 '13 at 03:34
  • Can you give me examples of urls you want to parse. The example you gave http://example.com/?hiyall is invalid unless ? is a regular expression. In which case http://example.com/shiyall is valid. – specialscope May 02 '13 at 03:44

2 Answers2

0

Do something like this in get(self):

class ParamHandler(webapp2.RequestHandler):
    def get(self):
        hyl = self.request.get("hiyall")
        self.response.out.write("hiyall was: " + hyl)

Customary official docs link: https://developers.google.com/appengine/docs/python/tools/webapp/requestclass#Request_get

0

If you're using webapp2, you cannot route requests based on parameters.

But you can create a condition based on query_string which can check if parameters exist. Like the following:

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)
Albert
  • 3,611
  • 3
  • 28
  • 52