我有以下项目
APP
|-static
|-templates
|-file.html
|-blueprints
|-blueprint1.py
|-blueprint2.py
|-app.py
每个blueprint文件都有不同的sanic
路由,我想在调用时呈现一个模板。在
我试着在每个blueprint
文件中放入以下内容
只为了得到错误ModuleNotFoundError: No module named 'APP'
将APP
替换为blueprints
会得到错误TypeError: expected str, bytes or os.PathLike object, not NoneType
我也试过使用这样的FileSystemLoader
template_loader = FileSystemLoader(searchpath="../static/templates")
template_env = Environment(loader=template_loader)
并加载我需要的模板template = template_env.get_template('file.html')
但是我在访问url时得到一个template not found
。在
直接尝试用
with open('..static/templates/file.html') as file:
template = Template(file.read())
再次导致file not found
错误。在
在我的应用程序中使用jinja
模板的最佳方式是什么?在
在这个项目中,我创建了一个项目,我将一个值呈现给jinja模板,它的工作很好,你可以看看这个我希望会有帮助: 这是项目树:
这是模板.html公司名称:
^{pr2}$这是应用程序副本公司名称:
输出:
相关问题 更多 >
编程相关推荐