Django 模板。我得到了我的邮件参数,我怎样才能将它们发送到另一个 html 包含?
Django templates. I get in my mail parameters, how can I send them to another html with include?
这是我的欢迎容器:
<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
你写 {% "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
您在模板中添加了 {% "Hi" %}
,其中 django 将 'Hi' 视为模板标记,但它在 django 中不存在,这就是它抛出错误的原因。您可能想在 title 变量前面添加 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 %}
这是我的欢迎容器:
<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
你写 {% "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
您在模板中添加了 {% "Hi" %}
,其中 django 将 'Hi' 视为模板标记,但它在 django 中不存在,这就是它抛出错误的原因。您可能想在 title 变量前面添加 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 %}