-1

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?

2 Answers2

5

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.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

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.

Mp0int
  • 18,172
  • 15
  • 83
  • 114