PackageLoader is defined as follows:
class PackageLoader(BaseLoader): """Load templates from python eggs or packages. It is constructed with the name of the python package and the path to the templates in that package:: loader = PackageLoader('mypackage', 'views') If the package path is not given, ``'templates'`` is assumed. Per default the template encoding is ``'utf-8'`` which can be changed by setting the `encoding` parameter to something else. Due to the nature of eggs it only possible to reload templates if the package was loaded from the file system and not a zip file. """
And then the __init__() method looks like this:
def __init__(self, package_name, package_path='templates', encoding='utf-8'):
This makes us notice that such a structure is as follows:
myapp/ __init__.py ... templates/ mytemplate.html
Will have the same PackageLoader instance with both of these declarations:
PackageLoader('myapp') PackageLoader('myapp', 'templates')
So, if you use the myapp/ path, you just need to say:
PackageLoader('templates', '')
So it just takes templates/ as a path. If you leave the second argument empty, it will try to find the templates in templates/templates .
Finally, you can check what was loaded using the list_templates() method:
PackageLoader('templates', '').list_templates()
fedorqui
source share