Skip to content
Advertisement

Javascript store in session, get from session in python/flask

I am working with a flask app, and am trying to store a Json object using javascript, and retrieve it in python as i would like to store a sort of “shopping list” information that the user is generating, into my database. The object appears in my browsers session storage

enter image description here

but it seems my syntax is off as im getting “KeyError: ‘routine'”

JavaScript

error log:

JavaScript

Advertisement

Answer

You’re getting a key error because when you write

JavaScript

Your code is trying to access the key ‘routine’ in the session object but it’s not there, so it’s throwing a key error.

You could modify it to:

JavaScript

Within flask you can also see what keys are in the session object by doing:

JavaScript

I don’t think flask logs stuff at info level by default, so for this to work you need to set logging to info level when you start your app. If that’s too fiddly just replace ‘app.logger.info’ with print.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement