Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何处理嵌套上下文?_Javascript_Python_Mustache - Fatal编程技术网

Javascript 如何处理嵌套上下文?

Javascript 如何处理嵌套上下文?,javascript,python,mustache,Javascript,Python,Mustache,我想在中使用嵌套字典,中的非假值部分建议这是可能的,并给出了以下示例: 模板: Hi Jon! {{{#个人?} 你好{{name}}! {{/人?} 散列: Hi Jon! { “人?”:{“姓名”:“乔恩”} } 输出: Hi Jon! 我尝试在中运行上述示例,得到: Hi ! 我也尝试过(pystache0.3.1、python2.7.2): 导入pystache tmpl=”“” {{{个人} 你好{{name}}! {{/人} """ dct={ “人”:{“姓名”:“乔恩

我想在中使用嵌套字典,中的非假值部分建议这是可能的,并给出了以下示例:

模板:

Hi Jon!
{{{#个人?}
你好{{name}}!
{{/人?}
散列:

Hi Jon!
{
“人?”:{“姓名”:“乔恩”}
}
输出:

Hi Jon!
我尝试在中运行上述示例,得到:

Hi !
我也尝试过(pystache0.3.1、python2.7.2):

导入pystache
tmpl=”“”
{{{个人}
你好{{name}}!
{{/人}
"""
dct={
“人”:{“姓名”:“乔恩”}
}
打印(pystache.render(tmpl,dct))
我犯了一个错误:

Traceback (most recent call last):
  File "test2.py", line 13, in <module>
    print(pystache.render(tmpl, dct))
  File "c:\Python27\lib\site-packages\pystache\__init__.py", line 7, in render
    return Template(template, context).render()
  File "c:\Python27\lib\site-packages\pystache\template.py", line 42, in render
    template = self.render_sections(template, context)
  File "c:\Python27\lib\site-packages\pystache\template.py", line 78, in render_sections
    insides.append(self.render(inner, item))
  File "c:\Python27\lib\site-packages\pystache\template.py", line 43, in render
    result = self.render_tags(template, context)
  File "c:\Python27\lib\site-packages\pystache\template.py", line 97, in render_tags
    replacement = func(self, tag_name, context)
  File "c:\Python27\lib\site-packages\pystache\template.py", line 105, in render_tag
    raw = context.get(tag_name, '')
AttributeError: 'str' object has no attribute 'get'
我可以通过输入dict预处理(将字典展平或更改为列表)来解决这个问题,但为什么它不起作用呢?我做错什么了吗


pystache问题的解法
位于的pystache版本非常旧(从2010年5月开始),这就是问题所在。来自的版本要新得多(嵌套字典的问题不会出现)。

除非我们知道
上下文发生了什么:

File "c:\Python27\lib\site-packages\pystache\template.py", line 43, in render
 result = self.render_tags(template, context)
File "c:\Python27\lib\site-packages\pystache\template.py", line 97, in render_tags
 replacement = func(self, tag_name, context)
File "c:\Python27\lib\site-packages\pystache\template.py", line 105, in render_tag
 raw = context.get(tag_name, '')
很难知道它为什么失败以及解决方案为什么成功,因为最后,
上下文
应该是
dict
而不是
str


我建议你把这一期交给pystache。他们会认真对待自己的问题。

除非我们知道
上下文发生了什么:

File "c:\Python27\lib\site-packages\pystache\template.py", line 43, in render
 result = self.render_tags(template, context)
File "c:\Python27\lib\site-packages\pystache\template.py", line 97, in render_tags
 replacement = func(self, tag_name, context)
File "c:\Python27\lib\site-packages\pystache\template.py", line 105, in render_tag
 raw = context.get(tag_name, '')
很难知道它为什么失败以及解决方案为什么成功,因为最后,
上下文
应该是
dict
而不是
str


我建议你把这一期交给pystache。他们认真看待自己的问题。

看起来pystache 0.3.1有点过时了。多亏了你们,我才直接从存储库中尝试了aersion,它工作正常。我认为在线演示是另一个问题。现在我需要检查Objective-C和Java版本是否按预期工作。看起来pystache 0.3.1有点过时了。多亏了你们,我才直接从存储库中尝试了aersion,它工作正常。我认为在线演示是另一个问题。现在我需要检查Objective-C和Java版本是否按预期工作。上面的示例在still中不起作用,因为它使用非常旧的版本(0.2.3-dev),其中最新版本是0.7.2,截至今天。上面的示例在still中不起作用,因为它使用非常旧的版本(0.2.3-dev),其中最新版本是0.7.2,截至今天。