点击最新文章的第一篇,会报错
list index out of range
Request Method: | GET |
---|---|
Request URL: | http://127.0.0.1:8000/blog/detail/23 |
Django Version: | 3.0.4 |
Exception Type: | IndexError |
Exception Value: | list index out of range |
Exception Location: | D:\python\lib\site-packages\django\db\models\query.py in __getitem__, line 296 |
Python Executable: | D:\python\python.exe |
Python Version: | 3.8.1 |
Python Path: | ['D:\\Webprojects\\django_introduction', 'E:\\', 'D:\\python\\python38.zip', 'D:\\python\\DLLs', 'D:\\python\\lib', 'D:\\python', 'D:\\python\\lib\\site-packages'] |
Server time: | Thu, 19 Mar 2020 06:29:09 +0000 |
这个问题的原因应该是在做上一篇和下一篇的时候出现了问题,导致取文章的值的时候数组溢出了。
遍历文章的下标应该去判断等于所有文章长度-1
list index out of range
23太多了,出界了