Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已将字典添加到对象中:
dict['var1'] = {'value': 'tetsing'}
object.dict = dict
现在我很困惑如何访问视图中的字典。我是否使用:
object.dict['var1']['value'] 或者object.dict.var1.value
object.dict['var1']['value']
object.dict.var1.value
首先,您应该重命名变量和属性名称,以免它们与内置名称(如dict.
dict
现在,在普通的 Python 代码中,使用第一种方式。
但是,如果您尝试从 Django 模板访问它,请使用第二个模板。