开发者

Django/python indexerror [duplicate]

开发者 https://www.devze.com 2023-02-17 16:15 出处:网络
This question already has answers here: 开发者_开发百科 Does "IndexError: list index out of range" when trying to access the N'th item mean that my list has less than N items?
This question already has answers here: 开发者_开发百科 Does "IndexError: list index out of range" when trying to access the N'th item mean that my list has less than N items? (7 answers) Closed 2 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号