Example #1
0
    def render_template(self,
                        email_template_file=None,
                        email_template_string=None,
                        encoding=None,
                        **kwargs):
        """设置邮件的html内容

        通过渲染兼容tornado.template格式的模板设置邮件正文
        参数email_template_file/email_template_string二选一

        Args:
            email_template_file:    HTML文件全路径
            email_template_string:  HTML文本字符串
            encoding:               HTML文件/字符串编码
            kwargs:                 渲染HTML模板用到的变量
        """

        self.write_content(
            tornadolib.render_string(
                (open(email_template_file).read()
                 if email_template_file else email_template_string),
                **kwargs).decode(encoding or self._encoding).encode('utf-8'))
Example #2
0
    def render_template(
        self,
        email_template_file=None,
        email_template_string=None,
        encoding=None,
        **kwargs
    ):
        """设置邮件的html内容

        通过渲染兼容tornado.template格式的模板设置邮件正文
        参数email_template_file/email_template_string二选一

        Args:
            email_template_file:    HTML文件全路径
            email_template_string:  HTML文本字符串
            encoding:               HTML文件/字符串编码
            kwargs:                 渲染HTML模板用到的变量
        """

        self.write_content(
            tornadolib.render_string(
                (open(email_template_file).read()
                 if email_template_file else email_template_string),
                **kwargs).decode(encoding or self._encoding).encode('utf-8'))
Example #3
0
 def test_render_string(self):
     print tornadolib.render_string("<li>{{ gen_sql_result('{{p_a}}') }}, {{ max([1,2,3]) }}</li>", gen_sql_result=gen_sql_result, p_a='Oul')