Python中不可信的模板什么是安全库?

2024-06-17 09:57:11 发布

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

我正在构建一个库,它将在几个Python应用程序中使用。它从RMDBS获取多语种的电子邮件模板,然后在发送电子邮件之前用Python语言对模板进行变量替换。在

除了变量替换,我还需要模板库来支持模板中的if、elif和for语句。在

我在我的大多数项目中都使用Mako,而且还研究了Tempita,因为它没有提供很多我不需要的特性。在

我担心的是不可信的代码执行——有人能告诉我一个Python模板解决方案,它要么不支持代码执行,要么允许我禁用它?在


Tags: 项目模板语言应用程序forif电子邮件mako
2条回答

Django book

For that reason, it’s impossible to call Python code directly within Django templates. All “programming” is fundamentally limited to the scope of what template tags can do. It is possible to write custom template tags that do arbitrary things, but the out-of-the-box Django template tags intentionally do not allow for arbitrary Python code execution.

试试Django templates。在Django应用程序之外设置与DJANGO_SETTINGS_MODULE有关的内容有点棘手,可以四处搜索,但可能是可信的。在

你退房了吗?这几乎就是你所说的,它是一个强大的组合,同时保持简单,不给设计师太多的权力。:)

如果您使用过Django的模板系统,它非常类似(如果不是基于的?)金贾。在

相关问题 更多 >