如何制作只包含jinja模板的python包

2024-09-29 23:30:42 发布

您现在位置:Python中文网/ 问答频道 /正文

目前有一个项目,我正在尝试扩展jinja2模板,这些模板位于我试图制作的python包中。现在我正在努力制作一个包含.html文件的python包。以下是我目前拥有的:

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

__init__.py为空,setup.py为超级基本。在

我当前使用的目录设置如下:

^{pr2}$

index.html中,我需要{% extends 'base.html' %}来扩展sharedtemplates包中的base。在

site.py中有这样的内容,可以优先加载模板:

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

app.jinja_loader = template_loader

所以这将在sharedtemplates/首先在我当前的repo dir中加载templates目录。在

谢谢。在


Tags: 项目py目录模板appjinja2baseinit

热门问题