Object does not support item assignment error

后端 未结 2 496
难免孤独
难免孤独 2021-02-01 12:19

In my views.py I assign values before saving the form. I used to do it the following way:

projectForm.lat = session_results[\'lat\']
projectForm.lng         


        
2条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 12:22

    Another way would be adding __getitem__, __setitem__ function

    def __getitem__(self, key):
        return getattr(self, key)
    

    You can use self[key] to access now.

提交回复
热议问题