I am working on a project that requires user login/logout. I have managed to pass data and store them in the localStorage. However, I cannot find the easiest way to integrate Flask with the localStorage file without using jQuery. I would love to have some suggestions from people who have already tried this out before. Here are my Python script and JavaScript code
Here is the Python Flask script:
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route("/login")
def login():
# DO SOMETHING TO AUTHENTICATE USER AND GENERATE TOKEN
return render_template("base.html", token="token")
@app.route("/logout")
def logout():
# RETRIEVE TOKEN FROM LOCAL STORAGE
return "Success"
if __name__ == '__main__':
app.run(debug=True)
Here is the HTML + JavaScript simplify code:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1> Hello </h1>
<script type="text/javascript">
// STORE TOKEN INTO LOCALSTORAGE
localStorage.setItem("token", "{{token}}");
</script>
</body>
</html>