我的情況很簡單:Django的多模板繼承
- 我有text/plain的郵件模板:body.txt
- 另外一個text/html類型的郵件:body.html
這兩封郵件的內容相同,因爲我使用EmailAlternative在同一封郵件中發送。
body.txt:
{% block message %}{% endblock %}
{{ site_name }} team
-----------------
If you need help contact use at {{ support_mail }}
body.html:
<html>
<head>
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<p>{% filter linebreaksbr %}{% block message %}{% endblock %}{% endfilter %}</p>
<p><strong>{{ site_name }} team</strong></p>
<hr/>
If you need help contact use at <a href="mailto:{{ support_mail }}">{{ support_mail }}</a>
</body>
</html>
當然是有翻譯,CSS和一個以上的塊多一點點複雜。
我的願望是定義invitation.txt:
{% block message %}Dear {{ first_name|title }} {{ last_name|upper }},
Your inscription has bee accepted. Welcome!
{% endblock %}
我希望能夠加載(body.txt,invitation.txt)以及(body.html,invitation.txt)至得到我的兩個html部分。
編輯:
類似的東西:
邀請/ body.txt:
{% extends body.txt invitation.txt %}
邀請/ body.html:
{% extends body.html invitation.txt %}
另一個想法:''{%if html%} {%extends base.html%} {%else%} {%extends base.txt%} {%endif%}' – Natim