ideas for conditional routing

37 views
Skip to first unread message

soujiro0725

unread,
Jul 28, 2012, 1:53:03 AM7/28/12
to google-a...@googlegroups.com
GAE for Python 1.7.0


We normally set up the routing like,

PAGE_RE = r'(/(?:[a-zA-Z0-9_-]+/?)*)'  
app = webapp2.WSGIApplication([('/?', MainPage),
                               ('/signup', Register),
                               ('/login', Login),
                               ('/logout', Logout),
                               ('/_upload', Upload),
                               ('/_accept', AcceptPost),
                               ('/?' + JSON_LIST_RE, JsonListHandler),
                               ('/(.*).json', JsonHandler),
                               ('/_edit' + PAGE_RE, EditPageHandler),
                               ('/_history' + PAGE_RE, HistoryHandler),
                               ('/?' + PAGE_RE, WordPageHandler),
                               ('/?' + LIST_RE, WordListPageHandler),
                               ('/(.*)', WordPageHandler)
                               ],
                              debug=True)

An appropriate handler is to be chosen in accordance with the regular expression and the order of the handlers.
But it is getting messy.  I need to clean things up.

So hopefully I would like to pass it through conditional statements.

class Conditional(Handler):
    def get(self, newpost):
        if "+" in newpost:
            self.response.write('choice 1')
        else:
            self.response.write('choice 2')

My question is How can I apply a handler IN the handler?

in the above Conditional(Handler): case, I tried to put 'WordPageHandler'.  Certainly it does not seem to work

class Conditional(Handler):
    def get(self, newpost):
        if "+" in newpost:
            WordPageHandler


Is is possible to set up nested handlers?




timh

unread,
Jul 28, 2012, 8:42:43 PM7/28/12
to google-a...@googlegroups.com
This is why I never use webapp and all the other RE based route methods.
I have used bobo (which just maps urls to objects)  http://bobo.digicool.com/ 

T
Reply all
Reply to author
Forward
0 new messages