How to make a python package containing only jinja templates

There is currently a project in which I am trying to extend the jinja2 templates that live in the python package that I am trying to do. Now I am trying to make a python package with .html files. Here is what I have now:

 sharedtemplates/ ├── setup.py └── templates ├── __init__.py ├── base.html ├── footer.html └── header.html 

__init__.py empty and setup.py is super basic.

I am currently working on a directory:

 repo/ ├── site.py └── templates └── index.html 

In index.html , I would have the {% extends 'base.html' %} base extension in the sharedtemplates package.

site.py has this place to prioritize template loading:

 template_loader = jinja2.ChoiceLoader([ jinja2.PackageLoader('reposhared', 'templates'), app.jinja_loader ]) app.jinja_loader = template_loader 

This way it will load dir templates in sharedtemplates / templates first / in my current repo.

Thanks.

0
source share
1 answer

I forgot to install setup.py python. And I needed to drop the templates into another template directory. So this is sharedtemplates / templates / templates / base.html. Definitely need to do some renaming and refactoring

0
source

All Articles