Home >Backend Development >Python Tutorial >How to Effectively Pass Variables Between Flask Pages?
Passing Variables Between Flask Pages
When navigating between routes in a Flask application, there may be a need to pass variables from one page to another for reuse. This article explores the different ways to accomplish this task, providing comprehensive solutions for both server-side and client-side scenarios.
Server-Side Techniques:
Session:
Example:
# Page A session['my_var'] = 'my_value' return redirect(url_for('b')) # Page B # ... my_var = session.get('my_var', None)
Client-Side Techniques:
Query Parameters:
Example:
<!-- Page A --> <a href="{{ url_for('b', my_var='my_value') }}">Send my_value</a> <!-- Page B --> # ... my_var = request.args.get('my_var', None)
The above is the detailed content of How to Effectively Pass Variables Between Flask Pages?. For more information, please follow other related articles on the PHP Chinese website!