Created
November 28, 2012 21:07
-
-
Save bensonk/4164496 to your computer and use it in GitHub Desktop.
An experiment with mutable global state in flask
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, abort, redirect, url_for | |
app = Flask(__name__) | |
class Datastore(object): | |
def __init__(self, **kwargs): | |
for k,v in kwargs.items(): | |
self.__setattr__(k, v) | |
ds = Datastore(who='World') | |
@app.route('/') | |
def hello(): | |
return 'Hello {}'.format(ds.who) | |
@app.route('/greet/<name>') | |
def greet(name): | |
ds.who = name | |
return redirect(url_for('hello')) | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I agree.