Home > Mobile >  Can you return a function in flask as well as return render_template?
Can you return a function in flask as well as return render_template?

Time:05-10

When you are writing a function within a certain @app.route, can you return a value for that function in addition to returning render_template?

What I am looking to code is an @app.route that finishes on render_template, but also passes the return of a function inside that @app.route to a different @app.route later on.

CodePudding user response:

No, it's not possible to do so directly - return value of function decorated with @app.route is automatically passed back by Flask as a page to the client (render_template return value is actually a HTML string representing the page), and the control flow is such that you can't simply "pass" arguments to a different @app.route. What you can do though, is store whatever you need in a global variable than can be accessed by different functions.

  • Related