flask pass list to another view

# Step 1: Import necessary modules
from flask import Flask, render_template

# Step 2: Create a Flask web application
app = Flask(__name__)

# Step 3: Define a route with a view that renders a template
@app.route('/')
def index():
    # Step 4: Create a list of data
    data_list = ['Item 1', 'Item 2', 'Item 3', 'Item 4']

    # Step 5: Pass the list to the template as a variable
    return render_template('index.html', data_list=data_list)

# Step 6: Define another route with a view that receives the list from the first view
@app.route('/another_view/<list_data>')
def another_view(list_data):
    # Step 7: Convert the string representation of the list back to a Python list
    received_list = eval(list_data)

    # Step 8: Perform any necessary operations with the received list
    # For example, you can render a template with the received list
    return render_template('another_view.html', received_list=received_list)

# Step 9: Run the Flask application
if __name__ == '__main__':
    app.run(debug=True)
<!-- Step 10: Create an HTML template (index.html) that displays the initial list -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Index</title>
</head>
<body>
    <h1>Data List</h1>
    <ul>
        {% for item in data_list %}
            <li>{{ item }}</li>
        {% endfor %}
    </ul>
    <a href="{{ url_for('another_view', list_data=str(data_list)) }}">Go to Another View</a>
</body>
</html>
<!-- Step 11: Create another HTML template (another_view.html) that displays the received list -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Another View</title>
</head>
<body>
    <h1>Received List</h1>
    <ul>
        {% for item in received_list %}
            <li>{{ item }}</li>
        {% endfor %}
    </ul>
</body>
</html>