从Django temp解析会话

2024-04-25 02:02:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我在django模板里找到了这个。你知道吗

{{request.session[0]}}

我有个错误:

Could not parse the remainder: '[0]' from 'request.session[0]'

当我在模板中使用{{request.session}}时,也会显示对象哈希,所以我猜数据传递是正常的,当我可以毫无问题地打印会话[0]时,为什么它可能无法在模板中工作?你知道吗


Tags: the数据对象djangofrom模板parserequest
1条回答
网友
1楼 · 发布于 2024-04-25 02:02:40

您可以使用模板中的.访问数组元素:

{{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])

相关问题 更多 >