diff --git a/docs/patterns/lazyloading.rst b/docs/patterns/lazyloading.rst index 8388102a..acb77f94 100644 --- a/docs/patterns/lazyloading.rst +++ b/docs/patterns/lazyloading.rst @@ -90,14 +90,19 @@ Then you can define your central place to combine the views like this:: You can further optimize this in terms of amount of keystrokes needed to write this by having a function that calls into :meth:`~flask.Flask.add_url_rule` by prefixing a string with the project -name and a dot, and by wrapping `view_func` in a `LazyView` as needed:: +name and a dot, and by wrapping `view_func` in a `LazyView` as needed. :: - def url(url_rule, import_name, **options): + def url(import_name, url_rules=[], **options): view = LazyView('yourapplication.' + import_name) - app.add_url_rule(url_rule, view_func=view, **options) + for url_rule in url_rules: + app.add_url_rule(url_rule, view_func=view, **options) - url('/', 'views.index') - url('/user/', 'views.user') + # add a single route to the index view + url('views.index', ['/']) + + # add two routes to a single function endpoint + url_rules = ['/user/','/user/'] + url('views.user', url_rules) One thing to keep in mind is that before and after request handlers have to be in a file that is imported upfront to work properly on the first