Domanda

I'm having difficulties with the gae webapp2 routing sistem.

In my routes.py I have the following:

_route  = [
RedirectRoute('/', 'home.HomeHandler', name='home', strict_slash=True),
RedirectRoute('/users/<usercode>', 'users.UserSingleHandler', name='user-page', strict_slash=True),
RedirectRoute('/users/comments/new/', 'users.UserNewCommentHandler', name='new-comment', strict_slash=True)
]

The problem I have is that when doing a ajax call to '/users/comments/new' the handler that receives the call is UserSingleHandler and not the one I need (UserNewCommentHandler). When inspecting the code, I found that de usercode param in UserSingleHandler gets '/comments/new/'... weird!!

¿What I'm doing wrong?

È stato utile?

Soluzione

Route like '/users/' will catch all requests on '/users/*', so you can fix your problem by changing the order of routes:

_route  = [
RedirectRoute('/', 'home.HomeHandler', name='home', strict_slash=True),
RedirectRoute('/users/comments/new/', 'users.UserNewCommentHandler', name='new-comment', strict_slash=True)
RedirectRoute('/users/<usercode>', 'users.UserSingleHandler', name='user-page', strict_slash=True),
]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top