Python ';元组';对象没有属性';有#u头';

Python ';元组';对象没有属性';有#u头';,python,django,dictionary,Python,Django,Dictionary,这是我的模板文件中的代码 {% load section_settings %} ## Loading a template tags {% section_settings declaration.id user.id as the_section_setting %} 现在,价值: the_section_setting = {'A': {'included': True, 'editable': True, 'alwaysIncluded': False, 'complete':Fals

这是我的模板文件中的代码

{% load section_settings %} ## Loading a template tags
{% section_settings declaration.id user.id as the_section_setting %}
现在,价值:

the_section_setting = {'A': {'included': True, 'editable': True, 'alwaysIncluded': False, 'complete':False}, 'C': {'included': False, 'editable': True, 'alwaysIncluded': False, 'complete': False}}
现在,在我的模板文件中,当我尝试在js脚本中运行此代码时:

<script type="text/javascript">

function initTree(showline){    
    {% for section in the_section_setting %}    
    alert("{{ the_section_setting[section]['included'] }}")
    {% endfor %}
        }   
</script>

正确的语法应该是

<script type="text/javascript">

function initTree(showline)
        {    
           {% for section, secval in the_section_setting.iteritems %}
           alert("{{secval.included}}")
           {% endfor %}
        }   
</script>

函数初始化树(显示行)
{    
{section的%s,在_section_setting.iteritems%}
警报(“{secval.included}}”)
{%endfor%}
}   
更详细地说,我会选择

<script type="text/javascript">

function initTree(showline)
        {    
           {% for section, secval in the_section_setting.iteritems %}
               {% if secval.include %}
                   alert("The {{ section }} is included.")
               {% else %}
                   alert(""The {{ section }} is not included.")
               {% endif %}
           {% endfor %}
        }   
</script>

函数初始化树(显示行)
{    
{section的%s,在_section_setting.iteritems%}
{%if secval.include%}
警报(“包括{{section}}}”)
{%else%}
警报(“{section}}不包括在内。”)
{%endif%}
{%endfor%}
}   

帮助文档-

我已经尝试了此
警报({{section.'included'}})
但是仍然是相同的错误我已经尝试过了,它没有显示任何错误。但是警报消息是空白的,不是正确的或错误的。如果我做了
警报({{section})
然后我会得到像
A
C
这样的值,这很好。但不是
包含的
键的值。在某个地方,您返回的是一个元组而不是响应对象。这就是为什么会出现错误。此外,您不应该混合和匹配javascript@AshishNitinPatil非常感谢Ashish,它运行良好很明显:)为什么不把你的回溯贴在这里?
<script type="text/javascript">

function initTree(showline)
        {    
           {% for section, secval in the_section_setting.iteritems %}
               {% if secval.include %}
                   alert("The {{ section }} is included.")
               {% else %}
                   alert(""The {{ section }} is not included.")
               {% endif %}
           {% endfor %}
        }   
</script>