开发者

App Engine CRUD with webapp - thoughts on structuring?

Two approaches:

# routes: (passed to WSGIApplication)
[..snip..]
('/note/add', AddNoteHandler),
('/note/delete/(.+)', DeleteNoteHandler),
('/note/view/(.+)', ViewNoteHandler),
('/note', ListNotesHandler),
[..snip..]

.. versus ..

('/note/(.*)', NoteHandler)

# which moves all the code from many RequestHandlers to one..
# ..but with a lot of branching inside, e.g.

class NoteHandler(webapp.RequestHandler):
    def get(self, params):
        params = params.split('/')
        action = params[0]
        开发者_开发知识库id = params[1]
        # start switching by action

     def post(self, params):
        params.split('/'):
            # POST case

Having separate handlers for each CRUD operation on some object (in this case, note) will result in a lot more code being repeated in those handlers, and a humongous route list. On the other hand, I feel this would have a much cleaner, nicer structure that the one-handler-for-all-of-crud way of doing it.

Any thoughts on this?


Have all of the handlers which share code subclass a base handler (which subclasses webapp.RequestHander).

That way you both have the routes and handlers separated properly and can factor out common code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜