2009-05-01 42 views
0

甲元史模板引发以下错误:是什么导致Genshi的模板语法错误?

TemplateSyntaxError: invalid syntax in expression "${item.error}" of "choose" directive

该错误指定为以下(“进料”是被传递给模板字典的列表)模板代码的一部分:

<item py:for="item in feed"> 
<py:choose error="${item.error}"> 
    <py:when error="0"> 
     <title>${item.something}</title> 
    </py:when> 
    <py:otherwise> 
     <title>${item.something}</title> 
    </py:otherwise> 
</py:choose> 
</item> 

基本上,item.error持有或者是'0''1',我想基于所述输出。我不知道错误在哪里 - 任何帮助表示赞赏。谢谢。

回答

0

我从来没有使用过Genshi,但是根据我发现的文档,它看起来像是试图在模板指令参数中使用内联Python表达式语法,这似乎是无用的。试试这个:

<item py:for="item in feed"> 
<py:choose error="item.error"> 
    <py:when error="0"> 
     <title>${item.something}</title> 
    </py:when> 
    <py:otherwise> 
     <title>${item.something}</title> 
    </py:otherwise> 
</py:choose> 
</item> 
+0

谢谢Jorenko。我自己意识到了这个错误并改变了它。但它仍然没有工作。我决定用两个if来代替,而且工作。 – Sam 2009-05-04 10:00:46

4

docs也许不明确这一点,但属性需要被调用test(因为它是在他们的例子),而不是error

<item py:for="item in feed"> 
<py:choose test="item.error"> 
    <py:when test="0"> 
     <title>${item.something}</title> 
    </py:when> 
    <py:otherwise> 
     <title>${item.something}</title> 
    </py:otherwise> 
</py:choose> 
</item>