从字符串而不是文件加载模板 [英] Load template from a string instead of from a file

查看:67
本文介绍了从字符串而不是文件加载模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定将所有系统电子邮件的模板保存在数据库中。
这些电子邮件的正文是正常的django模板(带标签)。



这意味着我需要模板引擎从字符串加载模板,而不是从一份文件。
有没有办法完成这个?

解决方案

实例化一个 django.template.Template() ,传递字符串作为模板。


I have decided to save templates of all system emails in the DB. The body of these emails are normal django templates (with tags).

This means I need the template engine to load the template from a string and not from a file. Is there a way to accomplish this ?

解决方案

Instantiate a django.template.Template(), passing the string to use as a template.

这篇关于从字符串而不是文件加载模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆