Search code examples
pythongoogle-app-engineroutesurl-routingwebapp2

Webapp2 strict_slash returns KeyError: 'Missing Argument' for url with trailing slash when method has 2 or more args... Bug?


I've built my urls as such:

#url = /index/test/argument/second
# Maps to the Index handler's test method and passes in the optional arguments 'argument' and 'second' 

# So the handler function looks like this:

def test(argument=None,second=None):
   print 'test'

I'm using strict_slash from webapp2 so the handlers with a trailing slash get redirected to handlers without a trailing slash.

#url = /index/ redirects perfectly to /index
#url = /index/test/ # KEYERROR!!

So even though index/test is routed before index/test/second, webapp2 is ignoring the redirect for trailing slashes and returning an error because it's looking (too hard) for the second argument. I think it should recognize there is no second argument so follow the strict_slash redirect route.

This works in all cases except with argument passing. Any insight, anyone?


Solution

  • To solve this problem you just need to set unique name argument for routes.