Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What <a href="http://pythonhosted.org/Flask-Classy/" rel="nofollow">flask-classy</a> does is create a temporary cache that it stores on the method, then it uses something else (the fact that Flask will register the classes using a <code>register</code> class method) to actually wraps the method.</p> <p>You can reuse this pattern, this time using a metaclass so that you can wrap the method at import time.</p> <pre><code>def route(rule, **options): """A decorator that is used to define custom routes for methods in FlaskView subclasses. The format is exactly the same as Flask's `@app.route` decorator. """ def decorator(f): # Put the rule cache on the method itself instead of globally if not hasattr(f, '_rule_cache') or f._rule_cache is None: f._rule_cache = {f.__name__: [(rule, options)]} elif not f.__name__ in f._rule_cache: f._rule_cache[f.__name__] = [(rule, options)] else: f._rule_cache[f.__name__].append((rule, options)) return f return decorator </code></pre> <p>On the actual class (you could do the same using a metaclass):</p> <pre><code>@classmethod def register(cls, app, route_base=None, subdomain=None, route_prefix=None, trailing_slash=None): for name, value in members: proxy = cls.make_proxy_method(name) route_name = cls.build_route_name(name) try: if hasattr(value, "_rule_cache") and name in value._rule_cache: for idx, cached_rule in enumerate(value._rule_cache[name]): # wrap the method here </code></pre> <p>Source: <a href="https://github.com/apiguy/flask-classy/blob/master/flask_classy.py" rel="nofollow">https://github.com/apiguy/flask-classy/blob/master/flask_classy.py</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload