python - Application-scope variables in Flask? -


is there such thing application-scope python variables in flask? i'd implement primitive messaging between users, , shared data cache. of course, possible implement via database, wanted know maybe there db-free , perhaps faster approach. ideally, if shared variable live python object, needs satisfied strings , ints, too.

edit: complemented (non-working) example

from flask import g  @app.route('/store/<name>') def view_hello(name=none):     g.name = name     return "storing " + g.name  @app.route("/retrieve") def view_listen():     n = g.name     return "retrieved: " + n 

at trying retrieve g.name, triggers error: attributeerror: '_requestglobals' object has no attribute 'name'

i'm unsure whether idea or not, i've been using share data between requests:

class myserver(flask):      def __init__(self, *args, **kwargs):             super(myserver, self).__init__(*args, **kwargs)              #instanciate variables here             self.messages = []  app = myserver(__name__)  @app.route("/") def foo():     app.messages.append("message") 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -