def paginate(self, page=None, per_page=None, error_out=True, max_per_page=None, count=True):
if request:<EOL><INDENT>if page is None:<EOL><INDENT>try:<EOL><INDENT>page = int(request.args.get('<STR_LIT>', <NUM_LIT:1>))<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>if error_out:<EOL><INDENT>abort(<NUM_LIT>)<EOL><DEDENT>page = <NUM_LIT:1><EOL><DEDENT><DEDENT>if per_page is None:<EOL><INDENT>try:<EOL><INDENT>per_page = int(request.args.get('<STR_LIT>', <NUM_LIT:20>))<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>if error_out:<EOL><INDENT>abort(<NUM_LIT>)<EOL><DEDENT>per_page = <NUM_LIT:20><EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if page is None:<EOL><INDENT>page = <NUM_LIT:1><EOL><DEDENT>if per_page is None:<EOL><INDENT>per_page = <NUM_LIT:20><EOL><DEDENT><DEDENT>if max_per_page is not None:<EOL><INDENT>per_page = min(per_page, max_per_page)<EOL><DEDENT>if page < <NUM_LIT:1>:<EOL><INDENT>if error_out:<EOL><INDENT>abort(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>page = <NUM_LIT:1><EOL><DEDENT><DEDENT>if per_page < <NUM_LIT:0>:<EOL><INDENT>if error_out:<EOL><INDENT>abort(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>per_page = <NUM_LIT:20><EOL><DEDENT><DEDENT>items = self.limit(per_page).offset((page - <NUM_LIT:1>) * per_page).all()<EOL>if not items and page != <NUM_LIT:1> and error_out:<EOL><INDENT>abort(<NUM_LIT>)<EOL><DEDENT>if not count:<EOL><INDENT>total = None<EOL><DEDENT>elif page == <NUM_LIT:1> and len(items) < per_page:<EOL><INDENT>total = len(items)<EOL><DEDENT>else:<EOL><INDENT>total = self.order_by(None).count()<EOL><DEDENT>return Pagination(self, page, per_page, total, items)<EOL>
Returns ``per_page`` items from page ``page``.

        If ``page`` or ``per_page`` are ``None``, they will be retrieved from
        the request query. If ``max_per_page`` is specified, ``per_page`` will
        be limited to that value. If there is no request or they aren't in the
        query, they default to 1 and 20 respectively. If ``count`` is ``False``,
        no query to help determine total page count will be run.

        When ``error_out`` is ``True`` (default), the following rules will
        cause a 404 response:

        * No items are found and ``page`` is not 1.
        * ``page`` is less than 1, or ``per_page`` is negative.
        * ``page`` or ``per_page`` are not ints.

        When ``error_out`` is ``False``, ``page`` and ``per_page`` default to
        1 and 20 respectively.

        Returns a :class:`Pagination` object.