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

Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>
This commit is contained in:
mvantellingen 2011-01-23 13:31:02 +01:00 committed by Armin Ronacher
parent 8a73097fe5
commit b0ca7e5af1
3 changed files with 46 additions and 0 deletions

View file

@ -145,3 +145,24 @@ Here the code for that decorator::
return render_template(template_name, **ctx)
return decorated_function
return decorator
Endpoint Decorator
------------------
When you want to use the werkzeug routing system for more flexibility you
need to map the endpoint as defined in the :class:`~werkzeug.routing.Rule`
to a view function. This is possible with this decorator. For example::
from flask import Flask
from werkzeug.routing import Rule
app = Flask(__name__)
app.url_map.add(Rule('/', endpoint='index'))
@app.endpoint('index')
def my_index():
return "Hello world"