Skip to content
Myr

Implement the endpoint decorator. This allows you to easily map views to endpoints when using the werkzeug routing.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by mvantellingen · committed by Armin Ronacher · parent 8a73097 · Browse files · 3 files+46 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>

Diff stats

3 files+46 added−0 removed

  • other:+46 added−0 removed

3 files+46 added−0 removed

modified:docs/patterns/viewdecorators.rst+21 added
143 unmodified lines
144 return ctx145 return render_template(template_name, **ctx)146 return decorated_function147 return decorator148149150Endpoint Decorator151------------------152153When you want to use the werkzeug routing system for more flexibility you154need to map the endpoint as defined in the :class:`~werkzeug.routing.Rule` 155to a view function. This is possible with this decorator. For example:: 156157 from flask import Flask158 from werkzeug.routing import Rule159160 app = Flask(__name__) 161 app.url_map.add(Rule('/', endpoint='index')) 162163 @app.endpoint('index') 164 def my_index(): 165 return "Hello world" 166167168
modified:flask/app.py+17 added
494 unmodified lines
495 provided.496 """497 options.setdefault('url_prefix', module.url_prefix)498 options.setdefault('subdomain', module.subdomain)499 self.view_functions.update(module.view_functions)500 state = _ModuleSetupState(self, **options)501 for func in module._register_events:502 func(state)503
125 unmodified lines
629 self.add_url_rule(rule, None, f, **options)630 return f631 return decorator632633634 def endpoint(self, endpoint):635 """A decorator to register a function as an endpoint.636 Example::637638 @app.endpoint('example.endpoint')639 def example():640 return "example"641642 :param endpoint: the name of the endpoint643 """644 def decorator(f):645 self.view_functions[endpoint] = f646 return f647 return decorator648649 def errorhandler(self, code):650 """A decorator that is used to register a function give a given651 error code. Example::652
313 unmodified lines
modified:flask/module.py+8 added
122 unmodified lines
123 _PackageBoundObject.__init__(self, import_name)124 self.name = name125 self.url_prefix = url_prefix126 self.subdomain = subdomain127 self.view_functions = {}128 self._register_events = [_register_module(self, static_path)]129130 def route(self, rule, **options):131 """Like :meth:`Flask.route` but for a module. The endpoint for the
25 unmodified lines
157 the_endpoint),158 view_func, **options)159 self._record(register_rule)160161 def endpoint(self, endpoint):162 """Like :meth:`Flask.endpoint` but for a module."""163 def decorator(f):164 self.view_functions[endpoint] = f165 return f166 return decorator167168 def before_request(self, f):169 """Like :meth:`Flask.before_request` but for a module. This function170 is only executed before each request that is handled by a function of171 that module.
59 unmodified lines