6
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

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.)

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Thanks! The suggestion would definitely have the advantages of improving readibility and maintainability. \$\endgroup\$ Commented Nov 9, 2011 at 9:37

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.