Passing Variables Between Flask Views

I needed to pass a list of error IP addresses from one Flask view to another. Flask views are just two different functions, they define the pages on the website.

The error IP list was created when on page devices/info and they are to be displayed on page devices/inventory as errors.

Method 1

This first method passes variables created in Python from one view to another.

Example Code

In Action in Scrapli & Flask Project

Method 2

This second method is slightly different as it is taking a variable created from WTForms.
WTForms allows the usage of forms in Flask. I have used them extensively.

The form has in this case IP addresses input. Upon submit those IP addresses are passed to a second view and printed in the console as a list.

The code I have used in the views.py file is below. I needed to get the data, otherwise it is only the memory reference that is refurned. The .data is then passed via the user session.
I have then split the data on a comma so I have a list to itterate over.

Leave a Comment

Your email address will not be published. Required fields are marked *