"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "docs/patterns/lazyloading.rst" between
flask-1.1.1.tar.gz and flask-1.1.2.tar.gz

About: Flask is a lightweight Python WSGI web application framework.

lazyloading.rst  (flask-1.1.1):lazyloading.rst  (flask-1.1.2)
skipping to change at line 61 skipping to change at line 61
app.add_url_rule('/user/<username>', view_func=views.user) app.add_url_rule('/user/<username>', view_func=views.user)
Loading Late Loading Late
------------ ------------
So far we only split up the views and the routing, but the module is still So far we only split up the views and the routing, but the module is still
loaded upfront. The trick is to actually load the view function as needed. loaded upfront. The trick is to actually load the view function as needed.
This can be accomplished with a helper class that behaves just like a This can be accomplished with a helper class that behaves just like a
function but internally imports the real function on first use:: function but internally imports the real function on first use::
from werkzeug import import_string, cached_property from werkzeug.utils import import_string, cached_property
class LazyView(object): class LazyView(object):
def __init__(self, import_name): def __init__(self, import_name):
self.__module__, self.__name__ = import_name.rsplit('.', 1) self.__module__, self.__name__ = import_name.rsplit('.', 1)
self.import_name = import_name self.import_name = import_name
@cached_property @cached_property
def view(self): def view(self):
return import_string(self.import_name) return import_string(self.import_name)
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)