Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
[Flask] Routing with class
from klask import Klask
app = Klask(__name__)
class Handler:
def hello(self, name):
return "Hello {name}!".format(name=name)
if __name__ == "__main__":
from flask import Flask
from functools import partial, update_wrapper
def compose(g, f):
return lambda *args, **kwargs: g(f(*args, **kwargs))
class Klask(Flask):
def __init__(self, *args, **kwargs):
Flask.__init__(self, *args, **kwargs)
def route(self, rule, **options):
apply_self = lambda f: update_wrapper(partial(f, self=None), f)
decorator = Flask.route(self, rule, **options)
return compose(decorator, apply_self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment