Skip to content

Instantly share code, notes, and snippets.

@bensonk
Created November 28, 2012 21:07
Show Gist options
  • Save bensonk/4164496 to your computer and use it in GitHub Desktop.
Save bensonk/4164496 to your computer and use it in GitHub Desktop.
An experiment with mutable global state in flask
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)
@errzey
Copy link

errzey commented Nov 28, 2012

I agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment