我正在使用django模板创建一个xml,它将我的一些变量(所有这些都来自python字典)输出为{'__unicode__': {}
但不是全部。 / p>
我看不到变量被破坏的模式....
这种情况发生的一般原因是什么?
以下是我正在运行的代码的粗略概念:
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,并且它在python 2.7上进行了“测试”。这在我的python解释器中不会发生。