Django/python indexerror [duplicate]
Exception Type: IndexError Exception Value: list index out of range
i Have a form which inherits a model from , on saving the form instance i am getting the above error. Can you please suggest the cause of this error?
The list has n
elements, and you're trying to index it at n
or greater. Restrict the index to between 0
and n-1
inclusive.
In such cases, there is a dictionary of elemnents , let me say:
lst = {1:"1",
2:"2",
3:"3",
4:"4",
5:"5",
7:"7",
8:"8",
9:"9"}
is a list of 8 numerics from 1 to 9 except 6.... If you try to get the value of element wth key 6, which is done using
lst[6]
your code returns you that error, becaouse ther eexists no key-value pair in your dictionary with key 6.
So your form returns a key that do not exist in your value dictionary. It is hard to say anything without seeing your code.
精彩评论