Habib Derbyshire
Habib Derbyshire

Reputation: 31

Flask: how to detect a user leaving a page?

I'm writing a Flask web app, and I want to call a function from views.py when a user leaves one specific page (closes the page or goes to another page). How do I do this?

Upvotes: 3

Views: 5117

Answers (1)

Sebastian Stigler
Sebastian Stigler

Reputation: 7289

You could use a websocket (i.e see https://flask-socketio.readthedocs.io/en/latest/#connection-events). You can register a disconnect handler function.

Upvotes: 2

Related Questions