Return RedirectResponse or jinja2Templates' TemplateResponse from an endpoint? · Issue #343 · pydantic/FastUI · GitHub
Skip to content
This repository was archived by the owner on Jun 7, 2026. It is now read-only.
This repository was archived by the owner on Jun 7, 2026. It is now read-only.

Return RedirectResponse or jinja2Templates' TemplateResponse from an endpoint? #343

Open

Description

@fmrib00

I need to redirect the page to some template HTML pages within a fastui endpoint procedure, for example, I need to show the home template page when home link is clicked. so I tried

@router.get('/home', response_model=FastUI, response_model_exclude_none=True)
def home(request: Request) -> list[AnyComponent]:
    return templates.TemplateResponse(
        name="home.html",
        context={"request": request}
    )

but then I will get

Request Error
Response not valid JSON

I am sure there must be a way to do it; I just didn't do it correctly. I would appreciate any help!

Activity

  1. changed the title [-]how do I return RedirectResponse or jinja2Templates' TemplateResponse from an endpoint?[/-] [+]Return RedirectResponse or jinja2Templates' TemplateResponse from an endpoint?[/+] on Aug 14, 2024
  2. fmrib00 commented on Sep 7, 2024

    @fmrib00
    Author

    Is there no way to go to a template HTML page from a FastUI end point? I just wanted to redirect to a login page once logout endpoint is triggered. What is the recommended way to handle login with a customer login page that is based on template?
    @zboyles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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