要求是根据从api接收到的bodydata发送模板邮件。 BodyData可能不包含某些标签。参见下面的样例模板部分。
class CreateAnswer(CreateView):
model = Answer
fields = ['answer']
def form_valid(self, form):
answer = form.save(commit=False)
profile = Profile.objects.get(user=self.request.user)
institution = Institution.objects.all()
question = Question.objects.filter(institution=institution)
answer.question = get_object_or_404(Answer, question=question)
answer.answerer = profile
return super().form_valid(form)
因此正文数据可能不包含teamName。因此,我想将if条件放在模板中的{{teamName}}上。
请在这里帮助我找到解决方法
答案 0 :(得分:2)
对于SES模板中的条件逻辑,可以使用if语句,就像在代码中那样。在您的示例中,您将使用
<p>{{sender}} has invited you to join team {{#if teamName}}{{teamName}}{{/if}}</p>
来自以下文档
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-advanced.html