Skip to content
Advertisement

Object is not subscriptable python error django

I have this function where i am using models ‘Start’ and ‘End’ that contain fields latitude and longitude.. and I am trying to match them with a field called elements that I am using subscript to extract the start_id and end_id and match them with ‘Start’ and ‘End’

The function in question that is giving me a subscript error is:

JavaScript

I am getting an error saying:

JavaScript

My Start model is:

JavaScript

Advertisement

Answer

Keep in mind that in your for loop the variables d['start'] and d['end'] each contain an instance of the Start model. To manipulate the fields of an instance you should use the dot . (you should use subscript when dealing with subscriptable objects – see What does it mean if a Python object is “subscriptable” or not?):

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement