python - Python3,jinja2,导入宏时出错
问题描述
我有以下python项目的结构:
myproject/
__init__.py
app.py
static_sql.sql
templates/
set_variables.sql
应用程序.py:
from jinja2 import Template, Environment, BaseLoader
with open("static_sql.sql") as f:
query = f.read().strip()
tm = Environment(loader=BaseLoader()).from_string(query)
print(tm.render())
静态sql.sql:
{%- from 'templates/set_variables.sql' import define_total_counts with context %}
delete from {{ schema }}.realtime_feature_score
where dw_date_key = {{ dw_date_key }}
and feature_model_id = {{ model_id }};
set_variables.sql:
{% macro define_total_counts(include_cardinality=False, render=False) -%}
{%- endmacro -%}
当我运行app.py时出现错误:
jinja2.exceptions.TemplateNotFound:模板/set_variables.sql
我应该如何纠正这个错误?
解决方案
推荐阅读
- heroku - 将mern堆栈部署到Heroku时如何访问反应页面?
- reactjs - 如何在另一个useQuery api调用中使用来自一个`useQuery`的响应?
- linux-kernel - Linux 内核编程:“无法使用 fs=KERNEL_DS 在虚拟地址 v 000000003a8ef000 处理内核对用户内存的访问”
- python - 检查值是否是其他列 Pandas Python 中值的一部分
- javascript - 如何保护将 Firebase 存储用于以下应用程序的网站?
- django-models - 将大量模型从 Foreigner Table 更新为 Django Rest 中的 Current Table
- javascript - 在 Angular 12 中过滤 NavigationEnd 事件?
- matlab - 运行 UNet 生物医学分割模型时出现 caffe.mexa64 的问题
- flutter - 列表视图中的特定文本在颤动中应该是不可滚动的
- websphere - 如何使用 IBM API 管理器的分析功能