You need to use JavaScript.
Python (the server side) knows nothing about JavaScript (the client side), where the local storage is located.
The easiest, though not the most effective way to solve the problem is
You have a JavaScript JS fragment running on your HTML page
This JS makes a server side AJAX request. Try jQuery.getJSON ()
Viewing flags returns JSON data
JS code gets JSON and saves it in localStorage
, , (JavaScript) cookie.