I have a JSON API in one blueprint module, and a web frontend in another one.
I would like to shave off a few AJAX requests the client JS code would have to make by embedding some of the JSON it'll need in the frontend view template, before sending it to the client, like in this gist I found.
How do I call one Flask view from another Flask view?
I could have called the view function directly, but request
would correspond to the “outer” request, and this confuses the called API function. I've tried using test_request_context
and it almost works but I can't figure out how to keep the authentication (I'm using Flask-Login).
request
object for generating pagination URLs and a few other things. I don't want to rewrite them all to explicitly passendpoint
,request.args
, etc. I also need this pagination info in the generated JSON so the client knows how to fetch the next page. I agree it's not the most elegant solution, but it works best for me.