我在django中使用内置的电子邮件系统,但现在我收到了这样的警告..
RemovedInDjango110Warning: render() must be called with a dict, not a Context
我的代码曾经是get_template(html_template).render(Context(body['ctx']))
我已经通过这样做了
get_template(html_template).render({Context(body['ctx'])})
但在我修复它之后,不知何故我不能再调用我的电子邮件模板中所需的变量了。
body['ctx']
实际上包含诸如
{'type': 'type1', 'field': 'field1}
之前,当我仍然使用警告方式发送电子邮件时,在电子邮件模板中我可以使用{{type}}
或{{field}}
但现在我修复了警告后,我再也无法调用变量了。我尝试将代码更改为get_template(html_template).render({'content': Context(body['ctx'])})
这仍然无效,在电子邮件模板中然后我尝试了{{content}}
我会得到类似这样的内容[{'False': False, 'None': None, 'True': True}, {'type': 'type1', 'field': 'field1'}]
所以我认为我可以通过执行{{ content.1.type }}
来调用类型变量,但仍然没有得到任何结果。
有人可以让我知道我可能做错了什么或者我可以在这里尝试什么?
提前致谢
答案 0 :(得分:1)
因为body['ctx']
已经是字典,所以你只需要在render()
函数中传递它。
get_template(html_template).render(body['ctx'])