[Fixed]-IndexError at /delta/ – list index out of range – Django

1👍

IndexError at /delta/ list index out of range. means that there is not data that was found by your model. You might want to look into your db to see whether those Ids exist or not. As per your code, there are no errors, so plz look at Aircraft.objects.filter(id__in=ids) a little more in deep.

Also its a good approach to use len(aircraft_to_compare) to check whether any data is present or not.

Hope this helps.

0👍

You may not have found any records in the query

aircraft_to_compare = Aircraft.objects.filter(id__in=ids)

Check the length of aircraft_to_compare or use try...except block while accessing items from that queryset.

0👍

In Views,
You are creating a list data=[], then you are appending some values in that list. So the problem is when the list is appended to its max length there is no space left to append more values "list out of range". You can try to make the list empty after each operation(comparison) using data.clear() .

Leave a comment