是什么导致了 Genshi 的模板语法错误?

发布于 2024-07-17 19:03:07 字数 641 浏览 5 评论 0原文

Genshi 模板引发以下错误:

TemplateSyntaxError:“choose”指令的表达式“${item.error}”中的语法无效

错误指定的模板代码部分如下 ( 'feed' 是传递给模板的字典列表):

<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'我想要基于此的输出。 我不确定错误在哪里 - 感谢任何帮助。 谢谢。

A Genshi template raises the following error:

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

The part of the template code that the error specifies is the following ('feed' is a list of dictionary which is passed to the template):

<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>

Basically, item.error holds either a '0' or a '1' and I want the output based on that. I am not sure where the error is - any help is appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

朦胧时间 2024-07-24 19:03:07

文档可能无法做到这一点清楚,但是该属性需要被称为 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>

The docs perhaps don't make this clear, but the attribute needs to be called test (as it is in their examples) instead of 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>
绳情 2024-07-24 19:03:07

我从未使用过 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>

I've never used Genshi, but based on the documentation I found, it looks like you're trying to use the inline Python expression syntax inside a templates directives argument, which seems to be unneccesary. Try this instead:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文