我正在开发的 Python 网站中使用 Chameleon。这是一段代码:
<option tal:repeat="option options"
value="${option.isoformat()}"
selected="${if request.get_param('%s%d%s' %(day, row, type))==option.isoformat(): 'selected'}">
${int(option.strftime('%I'))}${option.strftime(':%M%p')}
</option>
但出于某种原因,我总是遇到语法错误:
ExpressionError: invalid syntax
- String: "if request.get_param('%s%d%s' %(day, row, type))==option.isoformat(): 'selected'"
- Filename: /Users/theron/Sites/python/restaurateur/views/settings/hours.pt
我看不出我做错了什么。有帮助吗?
最佳答案
好吧,我想我明白了:它是无效的,因为没有 else 语句,所以当 if 语句评估为 false 时没有输出。我用以下方法修复了它:
<option tal:repeat="option options"
value="${option.isoformat()}"
tal:attributes="selected 'selected' if request.get_param('%s%d%s' %(day, row,
type))==option.isoformat() else None">
${int(option.strftime('%I'))}${option.strftime(':%M%p')}
</option>
关于python - 这个 ZPT 模板有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10199914/