|
|
@ -481,9 +481,9 @@ class Flask(object): |
|
|
|
""" |
|
|
|
""" |
|
|
|
session.save_cookie(response, self.session_cookie_name) |
|
|
|
session.save_cookie(response, self.session_cookie_name) |
|
|
|
|
|
|
|
|
|
|
|
def add_url_rule(self, rule, endpoint, **options): |
|
|
|
def add_url_rule(self, rule, endpoint, view_func=None, **options): |
|
|
|
"""Connects a URL rule. Works exactly like the :meth:`route` |
|
|
|
"""Connects a URL rule. Works exactly like the :meth:`route` |
|
|
|
decorator but does not register the view function for the endpoint. |
|
|
|
decorator. If a view_func is provided it will be registered with the endpoint. |
|
|
|
|
|
|
|
|
|
|
|
Basically this example:: |
|
|
|
Basically this example:: |
|
|
|
|
|
|
|
|
|
|
@ -495,19 +495,25 @@ class Flask(object): |
|
|
|
|
|
|
|
|
|
|
|
def index(): |
|
|
|
def index(): |
|
|
|
pass |
|
|
|
pass |
|
|
|
app.add_url_rule('index', '/') |
|
|
|
app.add_url_rule('/', 'index', index) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
If the view_func is not provided you will need to connect the endpoint to a |
|
|
|
|
|
|
|
view function like so: |
|
|
|
app.view_functions['index'] = index |
|
|
|
app.view_functions['index'] = index |
|
|
|
|
|
|
|
|
|
|
|
:param rule: the URL rule as string |
|
|
|
:param rule: the URL rule as string |
|
|
|
:param endpoint: the endpoint for the registered URL rule. Flask |
|
|
|
:param endpoint: the endpoint for the registered URL rule. Flask |
|
|
|
itself assumes the name of the view function as |
|
|
|
itself assumes the name of the view function as |
|
|
|
endpoint |
|
|
|
endpoint |
|
|
|
|
|
|
|
:param view_func: the function to call when servicing a request to the provided endpoint |
|
|
|
:param options: the options to be forwarded to the underlying |
|
|
|
:param options: the options to be forwarded to the underlying |
|
|
|
:class:`~werkzeug.routing.Rule` object |
|
|
|
:class:`~werkzeug.routing.Rule` object |
|
|
|
""" |
|
|
|
""" |
|
|
|
options['endpoint'] = endpoint |
|
|
|
options['endpoint'] = endpoint |
|
|
|
options.setdefault('methods', ('GET',)) |
|
|
|
options.setdefault('methods', ('GET',)) |
|
|
|
self.url_map.add(Rule(rule, **options)) |
|
|
|
self.url_map.add(Rule(rule, **options)) |
|
|
|
|
|
|
|
if view_func is not None: |
|
|
|
|
|
|
|
self.view_functions[endpoint] = view_func |
|
|
|
|
|
|
|
|
|
|
|
def route(self, rule, **options): |
|
|
|
def route(self, rule, **options): |
|
|
|
"""A decorator that is used to register a view function for a |
|
|
|
"""A decorator that is used to register a view function for a |
|
|
|