title: How to store my own variables on flask
body: <p>I need to define my own variables that would be saved on server while it's running. I am trying to use <code>flask.g</code> but it throws an error: </p>
  
  <pre><code>AttributeError: '_AppCtxGlobals' object has no attribute 'x'
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>from flask import *
  app=Flask(__name__)
  @app.route('/')
  def opa():
      #Added this to define variable
      try:
          g.x
      except NameError:
          g.x=None
      #Added this to add value to variable
      if g.x is None:
          g.x='Already defined'
          return 'x is now defined'
      else:
          return g.x
  if __name__ == "__main__":
      app.run(host='0.0.0.0',port=8081,debug=True)
  </code></pre>