redirect to different route_handler from a route_handler #3896
-
Often i find myself after processing some user-request that i want to return a different page for example, after editing a user (/usermanagement/{uid:int}/edit ) i want to redirect to the usermanagement-index-page, which i can do with a redirect of course... However - i'd like to "internally" reference the other routehandler and spare myself the unnecessary overhead of redirecting, and making the user retrieve more files than necessary again to load the whole page.. (especially since im using htmx to only return the necessary bits and pieces.) Is there some internal_redirect function which i just overlooked ? Before i just added some route_handler_cb-function which i referenced then from all http_route handlers, but this is very repetetive and every call needs to be adapted to changes introduced by dependency-injections or other parameters.. Anyone can point me in the right direction ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
There's no "internal redirect", but you can use |
Beta Was this translation helpful? Give feedback.
-
thanks - i agree that a lot more is happening here ( dependencies and middleware and so on).. that's exactly why i was looking for a way to jump into that resolution of the responsehandler.. however i do not agree that a redirect is "better" here.. it introduces a lot more overhead in regards of communication. i will go back to having separate functions which i call from the routehandlers (as i did before). i guess i just have to live with the adaptions necessary which i was trying to avoid. thanks in any case for diving into this and trying to provide a solution - much appreciated. |
Beta Was this translation helpful? Give feedback.
There's no "internal redirect", but you can use
app.route_reverse
to retrieve the path for a route handler by its name, and supply that to your redirect.