現在寫文章最大的動力就是,當遇到一個問題百度百試不靈的時候,纔會想到記錄下來。在說這個問題時不得不誇一下google和stackoverflow,什麼問題只要在百度中搜索不到,第一個想到的就是科學上網找解決方案,百試百爽。
其實template循環數字方法也很簡單,只需要稍稍動動腦子就可以了,就像下面找的答案裏說的一樣。這裏只是想明確一點,django有沒有內置直接循環數字的方法,像其它語言一樣
for(i=0;i<num;i++)
直接循環數字;
Unfortunately, that’s not supported in the Django template language. There are a couple of suggestions, but they seem a little complex. I would just put a variable in the context: