这是我的欢迎容器:
<tr>
<td align="center">
<!-- Start internal container -->
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td height="30" style="line-height:30px; font-size:30px;"> </td>
</tr>
<tr>
<td align="left" style="font-family: 'Lato', sans-serif; font-size:20px; line-height:26px;">
<p style="font-family: 'Lato', sans-serif; margin: 0; padding: 15px 60px 15px 60px; font-weight: bold; color: #333333;">
{{ title }}
</p>
<p style="font-family: 'Lato', sans-serif; font-size:16px; margin: 0; padding: 0px 60px 0px 60px; color: #333333;">
{{ subtitle }}
</p>
</td>
</tr>
</table>
<!-- End internal container -->
</td>
我尝试过:
{% "Hi {{first_name}}" as titleStr%}
{% with title=titleStr subtitle="Please confirm your email address by clicking this button." %}
{% include "emails/_parts/welcome_container.html" %}
{% endwith %}
但是我遇到了这个问题:
Invalid block tag on line 29: '"Hi', expected 'endblock'. Did you forget to register or load this tag?
我在做什么错?第29行是title = titleStr
答案 0 :(得分:0)
您编写{% "Hi
,并且django模板知道这是块标记的开始。如果只想显示文字,请将其更改为"Hi {{first_name}}"
如果您希望通过include传递变量,请尝试以下操作:
{% include "emails/_parts/welcome_container.html" with title={{first_name}} %}
包含https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#include的文档
答案 1 :(得分:0)
您已在模板中添加了{% "Hi" %}
,其中django将“ Hi”视为模板标签,但在django中不存在,这就是为什么它会引发错误。您可能希望在标题变量前面添加Hello,并将其传递给另一个模板。您可以通过add
模板标签来实现。
{% with "Hello "|add:first_name as titleStr %}
{% include 'emails/_parts/welcome_container.html' with title=titleStr subtitle="Please confirm your email address by clicking this button." %}
{% endwith %}