Decorators vs. classes in python web development.
Posted
by Tristan
on Stack Overflow
See other posts from Stack Overflow
or by Tristan
Published on 2010-06-06T16:56:56Z
Indexed on
2010/06/06
17:02 UTC
Read the original article
Hit count: 216
I've noticed three main ways Python web frameworks deal request handing: decorators, controller classes with methods for individual requests, and request classes with methods for GET/POST.
I'm curious about the virtues of these three approaches. Are there major advantages or disadvantages to any of these approaches? To fix ideas, here are three examples.
Bottle uses decorators:
@route('/')
def index():
return 'Hello World!'
Pylons uses controller classes:
class HelloController(BaseController):
def index(self):
return 'Hello World'
Tornado uses request handler classes with methods for types:
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
Which style is the best practice?
© Stack Overflow or respective owner