Skip to content

@jbpotonnier /.gitignore
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
[Flask] Routing with class
bin
include
lib
local
*.swp
*.pyc
from klask import Klask
app = Klask(__name__)
class Handler:
@app.route("/hello/<name>")
def hello(self, name):
return "Hello {name}!".format(name=name)
if __name__ == "__main__":
app.run(debug=True)
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
Something went wrong with that request. Please try again.