Database Information:

Code procedure:

``If __name__ == "__main__": user= user.query. Paginate (1,2) for I in user.iter_pages(): Print (I,end=" ") 1 2 3 4 5 None 8 9``

Today I took a look at the source code myself to analyze it

``def iter_pages(self, left_edge=2, left_current=2, right_current=5, right_edge=2): last = 0 for num in xrange(1, self.pages + 1): if num <= left_edge or (num > self.page - left_current - 1 and num < self.page + right_current) or num > self.pages - right_edge: if last + 1 ! = num: yield None yield num last = num``

It is clear that when last+1! = num returns None, so the next question is if I can make last+1! Num =, Num <= left_edge or (num < self.page – left_current – 1 and num < self.page + right_current) or num > self.pages – When right_edge does not hold, the next loop will set last+1! = num. So, how do we get to the point where a lot of people want a full traversal? This is to change the value of the default parameter so that one of the above three conditions is always true, such as num <= left_edge is always true

``For I in user.iter_pages(left_edge=user.pages): print(I,end=" "``

So that’s the perfect solution. And of course that makes it possible to do a complete traversal if any of these three conditions are true forever, but there are other ways to do it, and you can imagine that.