Skip to content
Discussion options

You must be logged in to vote

Hi @Kavan72,

You actually need to use add_pagination, without it code will not work.

Here is working example:

from typing import TypeVar

from fastapi import FastAPI
from pydantic import BaseModel

from fastapi_pagination import Page, add_pagination, paginate
from fastapi_pagination.customization import CustomizedPage, UseAdditionalFields

app = FastAPI()
add_pagination(app)

T = TypeVar("T")

class UserCount(BaseModel):
    active: int
    invited: int
    banned: int
    rejected: int

CustomPage = CustomizedPage[
    Page[T],
    UseAdditionalFields(
        extra=UserCount,
    ),
]

@app.get("/nums")
async def get_nums(is_admin: bool = False) -> CustomPage[int]:
    return paginate(
…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Kavan72
Comment options

Comment options

You must be logged in to vote
1 reply
@Kavan72
Comment options

Answer selected by Kavan72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants