I want to review the URL routing for my appengine webapp:

routes = [
        (r'/', CyberFazeHandler),
        (r'/vi/(eyes|mouth|nose)', CyberFazeHandler),
        (r'/realtime', RealtimeHandler),
        (r'/task/refresh-user/(.*)', RefreshUserHandler),
        ('/ai', FileUploadFormHandler),
        ('/serve/([^/]+)?', ServeHandler),
        ('/upload', FileUploadHandler),
        ('/generate_upload_url', GenerateUploadUrlHandler),
        ('/file/([0-9]+)', FileInfoHandler),
        ('/file/set/([0-9]+)', SetCategoryHandler),
        ('/file/([0-9]+)/download', FileDownloadHandler),
        ('/file/([0-9]+)/success', AjaxSuccessHandler),

app = webapp2.WSGIApplication(routes,
            debug=os.environ.get('SERVER_SOFTWARE', '').startswith('Dev'

Does it look alright to you? Can you recommend an improvement? Should I use the 'r prefix to my regexes?


Have you considered using named Route templates instead of capturing regular expressions? It could make the code more readable. Consider

Route("/task/refresh-user/<username>", RefreshUserHandler)

instead of

(r'/task/refresh-user/(.*)', RefreshUserHandler)

for example. (Of course, I don't know what kwargs RefreshUser actually wants, but you can change the angle-bracketed part to the appropriate name.)

  • 1
    \$\begingroup\$ Thanks! The suggestion would definitely have the advantages of improving readibility and maintainability. \$\endgroup\$
    – Niklas R.
    Nov 9 '11 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.