Rendering HTML emails with inline CSS using Jinja

回眸只為那壹抹淺笑 提交于 2021-01-26 09:46:55

问题


As you know, if you are going to send an HTML email, all CSS styling must be inline on the elements themselves e.g. <p style='font-family: Helvetica'>

Is there a way I can use Jinja to easily create HTML email bodies from Jinja templates without repeating CSS styles many times in a single template?

I think of setting these styles to variables e.g.

{% set FONT_STYLE = 'font-family: Helvetica; color: #111' %}

and then in the template I can do

<p style='{{ FONT_STYLE }}'>My paragraph here.</p>

Any better ideas? Maybe a library that resolves CSS rules that takes HTML content and CSS file and binds calculated CSS rules to the HTML elements one by one?


回答1:


Look at premailer which turns CSS blocks into style attributes. You can get pretty html and convert it to email html with premailer.



来源:https://stackoverflow.com/questions/16135394/rendering-html-emails-with-inline-css-using-jinja

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!