flash not defined python flask

from flask import Flask, render_template, flash, request, redirect, url_for

app = Flask(__name__)
app.secret_key = 'your_secret_key'

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/process_form', methods=['POST'])
def process_form():
    if request.method == 'POST':
        data = request.form['data']
        flash(f'You entered: {data}')
        return redirect(url_for('index'))

if __name__ == '__main__':
    app.run(debug=True)
  1. Import necessary modules from the Flask framework.
  2. Create a Flask web application instance.
  3. Set a secret key for the application to enable the use of session.
  4. Define a route for the home page ('/'), which renders an 'index.html' template.
  5. Define a route for processing form submissions ('/process_form') with the POST method.
  6. Check if the request method is POST, retrieve the form data, and flash a message with the entered data.
  7. Redirect the user back to the home page after processing the form.
  8. Run the Flask application in debug mode if the script is executed directly.