django django 模板中的输出呈现为 {'__unicode__': {}}
Output in django django template is rendered as {'__unicode__': {}}
我正在使用 Django 模板创建一个 xml,它输出我的一些变量(所有变量都来自 python 字典)作为 {'__unicode__': {}
但不是全部.
我看不到变量被破坏的模式....
发生这种情况有一般原因吗?
这是我的代码的粗略概念 运行:
from addict import Dict
def get_dictionary(self, orig_dict):
new_dict = Dict({'default_key':'default_value'})
if(orig_dict["code"]==0):
new_dict.other_key = "Double Quoted String"
elif(orig_dict["code"]==1):
new_dict.other_key = "Different Double Quoted String"
return new_dict
最终,当我将它与 render_to_string("xml_template.xml",dictionary=context_dictionary)
一起用于此模板时:
<ParentTag>
<MyFirstTag>{{new_dict.default_key}}</MyFirstTag>
<MySecondTag>{{new_dict.other_key}}</MySecondTag>
</ParentTag>
它呈现为:
<ParentTag>
<MyFirstTag>default_value</MyFirstTag>
<MySecondTag>{'__unicode__': {}</MySecondTag>
</ParentTag>
所以我不知道是 addict
还是其他什么。该软件包中似乎没有任何内容使用 unicode,它是 'tested' on python 2.7。这不会发生在我的 python 解释器中。
这是瘾君子发送空字典的方式。 It's broken.
这只是意味着您正在尝试访问一个不存在的字典值。
我正在使用 Django 模板创建一个 xml,它输出我的一些变量(所有变量都来自 python 字典)作为 {'__unicode__': {}
但不是全部.
我看不到变量被破坏的模式....
发生这种情况有一般原因吗?
这是我的代码的粗略概念 运行:
from addict import Dict
def get_dictionary(self, orig_dict):
new_dict = Dict({'default_key':'default_value'})
if(orig_dict["code"]==0):
new_dict.other_key = "Double Quoted String"
elif(orig_dict["code"]==1):
new_dict.other_key = "Different Double Quoted String"
return new_dict
最终,当我将它与 render_to_string("xml_template.xml",dictionary=context_dictionary)
一起用于此模板时:
<ParentTag>
<MyFirstTag>{{new_dict.default_key}}</MyFirstTag>
<MySecondTag>{{new_dict.other_key}}</MySecondTag>
</ParentTag>
它呈现为:
<ParentTag>
<MyFirstTag>default_value</MyFirstTag>
<MySecondTag>{'__unicode__': {}</MySecondTag>
</ParentTag>
所以我不知道是 addict
还是其他什么。该软件包中似乎没有任何内容使用 unicode,它是 'tested' on python 2.7。这不会发生在我的 python 解释器中。
这是瘾君子发送空字典的方式。 It's broken.
这只是意味着您正在尝试访问一个不存在的字典值。