Skip to content
Myr

Documented non-decorator uses of registation.

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

authored by Armin Ronacher · committed by Armin Ronacher · parent a9d4ea8 · Browse files · 1 file+31 added−5 removed
This commit

State

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

Diff stats

1 file+31 added−5 removed

  • other:+31 added−5 removed

1 file+31 added−5 removed

modified:flask.py+31 added-5 removed
286 unmodified lines
287 """288 if session is not None:289 session.save_cookie(response, self.session_cookie_name)290291 def add_url_rule(self, endpoint, **options):292 """Connects a URL rule. Works exactly like the :meth:`route`293 decorator but does not register the view function for the endpoint.294295 Basically this example::296297 @app.route('/')298 def index():299 pass300301 Is equivalent to the following:302303 def index():304 pass305 app.add_url_rule('index', '/')306 app.view_functions['index'] = index307 """308 options['endpoint'] = f.__name__309 options.setdefault('methods', ('GET',))310 self.url_map.add(Rule(rule, **options))311312 def route(self, rule, **options):313 """A decorator that is used to register a view function for a314 given URL rule. Example::315
55 unmodified lines
371 :param strict_slashes: can be used to disable the strict slashes372 setting for this rule. See above.373 """374 def decorator(f):354 if 'endpoint' not in options:355 options['endpoint'] = f.__name__356 options.setdefault('methods', ('GET',))357 self.url_map.add(Rule(rule, **options))358 self.view_functions[options['endpoint']] = f375 self.add_url_rule(f.__name__, **options)376 self.view_functions[f.__name__] = f377 return f378 return decorator379380 def errorhandler(self, code):
2 unmodified lines
383384 @app.errorhandler(404)385 def page_not_found():386 return 'This page does not exist', 404387388 You can also register a function as error handler without using389 the :meth:`errorhandler` decorator. The following example is390 equivalent to the one above::391392 def page_not_found():393 return 'This page does not exist', 404394 app.error_handlers[404] = page_not_found395 """396 def decorator(f):397 self.error_handlers[code] = f398 return f
125 unmodified lines