We could consider opening the cursor in before_request and closing it in after_request.
It might be better to include the opening of connections and cursors in a decorator and to use that decorator only on functions that actually read the database (not all do, for example /index does not).
It also looks like at the moment we are querying the database for no reason in before_request because the data is already stored in the session from the login.
We could consider opening the cursor in before_request and closing it in after_request. It might be better to include the opening of connections and cursors in a decorator and to use that decorator only on functions that actually read the database (not all do, for example /index does not). It also looks like at the moment we are querying the database for no reason in before_request because the data is already stored in the session from the login.