2024-04-25 02:02:40 发布
网友
我在django模板里找到了这个。你知道吗
{{request.session[0]}}
我有个错误:
Could not parse the remainder: '[0]' from 'request.session[0]'
当我在模板中使用{{request.session}}时,也会显示对象哈希,所以我猜数据传递是正常的,当我可以毫无问题地打印会话[0]时,为什么它可能无法在模板中工作?你知道吗
{{request.session}}
您可以使用模板中的.访问数组元素:
.
{{request.session.0}}
从wiki:
Dot lookups can be summarized like this: when the template system encounters a dot in a variable name, it tries the following lookups, in this order:
Dictionary lookup (e.g., foo["bar"]) Attribute lookup (e.g., foo.bar) Method call (e.g., foo.bar()) List-index lookup (e.g., foo[2])
您可以使用模板中的
.
访问数组元素:从wiki:
相关问题 更多 >
编程相关推荐