Meghdeep Ray
Meghdeep Ray

Reputation: 5537

Custom Decorators in Tornado

I'm facing an error while trying to make a custom tornado decorator.

TypeError: post() missing 1 required positional argument: 'self'

The sample code is:

def decorate( function_name ):
    # Do something
    function_name()
    # Do something

class MainHandler( tornado.web.RequestHandler ):
    @decorate
    def post( self ):
        # Do whatever

How do I pass the context of self to the decorator ?

Upvotes: 0

Views: 890

Answers (1)

xyres
xyres

Reputation: 21834

It seems you're not passing the arguments from the decorator to the decorated method.

Here's how your decorator should look like:

def decorate(func):
    def wrapper(*args, **kwargs):
        # pass the received arguments to
        # the decorated function
        return func(*args, **kwargs)
    return wrapper

Upvotes: 3

Related Questions