Sunday, 15 July 2012

python - Jinja2 for Flask not picking up child templates -


I am trying to write an email HTML file with three parts: headers, body and footers. This is a primary mail .html are wrapped inside a file that looks like this:

  & lt; Html & gt; & Lt; Body & gt; & Lt; P & gt; & Lt; Table border = "0" cellpadding = "0" style = "font-size: 12.727272033691406px; line-height: 1.2mm; font-family: 'helvetia new', helvetica, ariel, without-limit-spacing: 0 pixels; Border-right-width: 0 px; border-bottom-width: 0 px; border-left-width: 0 px; background-color: RGB (231, 232, 232); border-top-style: solid; Top-color: RGB (221, 221, 221); "width =" 100% "& gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; Td align = "center" style = "font-family: arial, sans-serif; margin: 0 pixels;" Width = "100%" & gt; {% Block head%} {% endblock%} {% block entity%} {% endblock%} & lt; Br / & gt; {% Block Furs%} {% endblock%} & lt; / Td> & Lt; / TR & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; / P & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

Originally a parent template with three basic templates, all in one directory. The hair templates have been described between the following two tags:

  {% "extends <%" mail.html "%} {% block head%} ... {% endblock%}  

When I run the following commands: Import from jinja2, packageloader env = environment (loader = packageloader ('MailAccess', 'Mail_templates' )) Template = env. Get_template ('mail.html') Template.Reder ()

I get output with the html of mail.html , but ignoring the hair blocks Instead, only empty lines are printed to get content in head ,

Em> body or footer block, you head.html template or body.html Or footer should present. Html . When you execute the head.html template, it takes the mail.html template and changes the block with the content. On the other hand, when you Mail.html template, the template is not known about the head.html (or other) template, which should replace the block with content

< P> Consider the following example.

mail.html

  & lt; Html & gt; & Lt; Body & gt; {% Block head%} {% endblock%} & lt; / Body & gt; & Lt; / Html & gt;  

head.html:

  extended {% block head%} {% "mail.html"%} Genie2 Import Environment, {{endpoint%}  

from the environment (loader =), the packageloader env = Mail-on ',' mail_templates')) template = env.get_template ('head.html') print (template.reader ()) & gt; & Gt; & Gt; & Lt; Html & gt; & Gt; & Gt; & Gt; & Lt; Body & gt; & Gt; & Gt; & Gt; Hello Email Head & gt; & Gt; & Gt; & Lt; / Body & gt; & Gt; & Gt; & Gt; & Lt; / Html & gt; Template = env.get_template ('mail.html') Print (template.reader ()) & gt; & Gt; & Gt; & Lt; Html & gt; & Gt; & Gt; & Gt; & Lt; Body & gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Lt; / Body & gt; & Gt; & Gt; & Gt; & Lt; / Html & gt;

I would recommend a bunch of 1 main mail.html template and other templates with 1 blocks which will be sent to the mail.html template , Place the material in all 3 blocks. For example

friendly_mail.html:

  {% "mail.html"%} extended {% block major%} is .. ., {% Endblock%} {% block entity%} You have a good day. {% Endblock%} {% Block Footer%} Sincerely, ... {% endblock%}  

No comments:

Post a Comment