iftekharjoy / webapp-improved

Automatically exported from code.google.com/p/webapp-improved
Other
0 stars 0 forks source link

webapp2.Route(r'/.*', ...) doesn't seem to work #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Setup a webapp2 route for general not found handling (last route)

2.e.g webapp2.Route(r'/.*', 'handlers.misc.NotFoundHandler', 
name='misc-not_found')

What is the expected output? What do you see instead?
I was expecting the route to work, note that similar route, works in webapp
e.g  (r'/.*', handlers.misc.NotFoundHandler)

What version of the product are you using? On what operating system?
Latest. 

Please provide any additional information below.
I realize that I could use  app.error_handlers[404] mechanism, but I rather 
not, because it dispatches to a function and not to a handler (for legacy 
reasons, I rather not dispatch to a function)

Original issue reported on code.google.com by ubaldo on 2 Aug 2011 at 11:43

GoogleCodeExporter commented 8 years ago
Hi,
You are using it incorrectly. All regular expressions inside a route template 
must be enclosed by <>. So to set a "catch all" route you must use:

webapp2.Route(r'/<:.*>', 'handlers.misc.NotFoundHandler', name='misc-not_found')

Or you could use a simple tuple (then it is pure regexp):

(r'/.*', 'handlers.misc.NotFoundHandler')

See the regex template explanation is here:

http://webapp-improved.appspot.com/guide/routing.html#the-regex-template

Also, you can mix tuples and webapp2.Route() instances in the routes list, as 
you wish.

Original comment by rodrigo.moraes on 3 Aug 2011 at 12:35