【发布时间】:2019-02-20 12:14:56
【问题描述】:
我想在 django 模板中显示字典的特定键的值。
dict1 = {'Device.Bridging.': '0', 'Device.': '0', 'Device.XMPP.SupportedServerConnectAlgorithms': '0'}
例如:我想显示键“Device.XMPP.SupportedServerConnectAlgorithms”的值
这就是我尝试访问该值的方式。
<div>
<p>{{dict1.Device.XMPP.SupportedServerConnectAlgorithms}}</p>
</div>
但是上面的代码给出的是空值。
和
<div>
<p>{{dict1["Device.XMPP.SupportedServerConnectAlgorithms"]}}</p>
</div>
Exception Type: TemplateSyntaxError
Exception Value:
Could not parse the remainder: '["Device.XMPP.SupportedServerConnectAlgorithms"]' from 'pvals["Device.XMPP.SupportedServerConnectAlgorithms"]'
【问题讨论】:
-
你没有使用 Jinja2。您正在使用 Django 模板语言。
-
我想你可以在这里找到解决方案:stackoverflow.com/questions/11801061/…
-
@DanielRoseman 我已经更新了,谢谢
-
@SergeyPugach 我尝试了您共享的链接中提供的解决方案,但出现以下错误。无法解析剩余部分:来自 'pvals["Device.XMPP.SupportedServerConnectAlgorithms"]' 的 '["Device.XMPP.SupportedServerConnectAlgorithms"]'
-
那你根本没有关注 Sergey 的链接。
标签: django python-3.x