0
在django文檔中提到。符號會做一個查找按照下面的順序如何在鍵有特殊字符時做Django模板字典查找?
#Dictionary lookup. Example:
foo["bar"]
#Attribute lookup. Example:
foo.bar
#List-index lookup. Example:
foo[bar]
在我的項目我有一本字典:
foo = {'ba-r':'...}
但使用。符號會導致錯誤,這似乎是因爲整個'foo.ba-r'是一個變量,如文檔here中所述。
foo.ba-r
有什麼方法可以正確訪問我的字典中的'ba-r'鍵嗎?
你有沒有理由不能使用foo [「ba-r」]? –
可能的重複[如何從Django模板中訪問包含連字符的字典鍵?](http://stackoverflow.com/questions/8252387/how-do-i-access-dictionary-keys-that-contain-連字符在django-templa中)和[在Django模板中使用空格鍵的字典](http://stackoverflow.com/questions/1906129/dict-keys-with-spaces-in-django-templates) – solarissmoke