Reputation: 329
I am trying to use webapp2 routing and this is currently failing. It does not seem to match the routing rules I set up and as a result returns a 404 for certain rules.
My code is like:
main.py
import webapp2, urls
app = webapp2.WSGIApplication(urls.SITE_URL_PATTERNS, debug=True)
urls.py
from webapp2 import Route
from webapp2_extras import routes
import test_handler
SITE_URL_PATTERNS = [
routes.PathPrefixRoute('/admin', [
Route(r'/action_one', test_handler.take_action_one),
Route(r'/action_two', test_handler.take_action_two),
Route(r'/<action_three:\w+>', test_handler.take_action_three),
]),
Route(r'/view/action_one', test_handler.view_action_one),
Route(r'/', test_handler.view_homepage),
]
app.yaml
- url: .*
script: main.app
I can not seem to load /view/action_one (returns a 404), but I can load /admin/action_one.
Any suggestions on what I am doing wrong here? Appreciate your help!
Upvotes: 0
Views: 678
Reputation: 329
Okay, I found my stupid error (yes, a real "DOH!" moment):
Route(r'/<action_three:\w+>'
Should be
Route(r'/<action_three:[^/]+>'
It had problems matching the datastore keys as these can include other characters that are represented by \w. Going for everything else but / will normally solve this problem (use [^/]+).
Hope this will help someone else as well.
Upvotes: 1