如何制作一个只包含jinja模板的python包 [英] How to make a python package containing only jinja templates
问题描述
.html
文件创建一个python包。这是我现在有的: sharedtemplates /
├──setup.py
└──模板
├──__init__.py
├──base.html
├──footer.html
└──header.html
目前我正在处理的目录是这样设置的: 在 目录共享模板/首先模板/在我目前的回购目录。 谢谢。 我忘了做python setup。 py安装。我需要将模板放在另一个模板目录中。所以它是共享模板/模板/模板/ base.html。绝对需要做一些重命名和重构 Currently have a project where I am currently trying to extend jinja2 templates that live in a python package I am trying to make. Right now I'm struggling to make a python package with The directory I am currently working on is setup like this: In So this would load the templates dir in sharedtemplates/ first the templates/ in my current repo dir. Thank you. I forgot to do python setup.py install. And I needed to throw the templates in another templates dir. So it is sharedtemplates/templates/templates/base.html. Definitely need to do some renaming and refactoring 这篇关于如何制作一个只包含jinja模板的python包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! __ init __。py
为空, setup.py <
repo /
├──site.py
└──模板
└──index.html
index.html
我会有 {%extends'base .html'%}
在 sharedtemplates
包中扩展基础。
site.py
有这个优先模板加载的优先次序:
template_loader = jinja2.ChoiceLoader([
jinja2.PackageLoader('reposhared','templates'),
app.jinja_loader
])
app.jinja_loader = template_loader
.html
files. Here is what I currently have:sharedtemplates/
├── setup.py
└── templates
├── __init__.py
├── base.html
├── footer.html
└── header.html
__init__.py
is empty and setup.py
is super basic.repo/
├── site.py
└── templates
└── index.html
index.html
I would have {% extends 'base.html' %}
to extend base in the sharedtemplates
package. site.py
has this in there to prioritize the template loading:template_loader = jinja2.ChoiceLoader([
jinja2.PackageLoader('reposhared', 'templates'),
app.jinja_loader
])
app.jinja_loader = template_loader