Created
October 25, 2022 23:59
-
-
Save askedrelic/441f3f1b8eb5caa7ac46fc53586f85f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, session | |
app = Flask(__name__) | |
app.session = dict() | |
@app.route('/') | |
def reset(): | |
app.session["counter"]=0 | |
return "counter was reset" | |
@app.route('/inc') | |
def routeA(): | |
if not "counter" in app.session: | |
app.session["counter"]=0 | |
app.session["counter"]+=1 | |
return "counter is {}".format(app.session["counter"]) | |
@app.route('/dec') | |
def routeB(): | |
if not "counter" in app.session: | |
app.session["counter"] = 0 | |
app.session["counter"] -= 1 | |
return "counter is {}".format(app.session["counter"]) | |
if __name__ == '__main__': | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, session | |
from flask_session import Session | |
app = Flask(__name__) | |
# Check Configuration section for more details | |
SESSION_TYPE = 'filesystem' | |
app.config.from_object(__name__) | |
Session(app) | |
@app.route('/') | |
def reset(): | |
session["counter"]=0 | |
return "counter was reset" | |
@app.route('/inc') | |
def routeA(): | |
if not "counter" in session: | |
session["counter"]=0 | |
session["counter"]+=1 | |
return "counter is {}".format(session["counter"]) | |
@app.route('/dec') | |
def routeB(): | |
if not "counter" in session: | |
session["counter"] = 0 | |
session["counter"] -= 1 | |
return "counter is {}".format(session["counter"]) | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment