Search code examples
pythonregexgoogle-app-enginehttpwebapp2

webapp2 python regex in routing


I'm trying to get webapp2 to handle urls in the form:

/case/e3627

where 'e3627' can be any alphanumeric string

Here is my routing arguments:

app = webapp2.WSGIApplication([(r'/case/<:^\w+$>', ViewCase)],
                              debug=True)

But I get a 404 error for my urls

I also tried <:^[a-zA-Z0-9_]+$> for the regex but no luck

My app works fine for regular urls for example /home but not for the regex

Any ideas?


Solution

  • I think

    app = webapp2.WSGIApplication([(r'/case/(\w+)', ViewCase)],
                                  debug=True)
    

    should suffice.

    Note that ^ means the beginning of the string, which clearly never occurs after /case/. I think that is why your regex did not work.