Skip to content

Lazy gettext with FastAPI response_model #51

@phamvanvuhb1999

Description

@phamvanvuhb1999

Hi, I'm facing some errors related to lazy gettext with FastAPI response_model,
It seem like lazytext not be evaluated correctly.
`
error_message = _("Some error message")

@app.get("/multilingual/template", response_class=JSONResponse)
async def multilingual_template(request: Request):
raise HTTPException(status_code=400, detail=error_message)

@app.get("/multilingual/template", response_class=JSONResponse)
async def multilingual_template(request: Request):
return {"data": error_message}
`
then both 2 endpoints raises "Lazytext is not Jsonable".

As I know, lazytext be evaluated (translated to string) when it needed, But how to force to do the translation in the view itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions