title: Flask: How do I get the returned value from a function that uses @app.route decorator?
body: <p>So I'm pretty new to Flask and I'm trying to make my mind around one thing. So, if I understand well when you write a function within a Flask app and you use the @app.route decorator in that function, it only runs when you hit that path/url.</p>
  
  <p>I have a small oauth app written in Flask that goes through all the authorization flow and then it return the token. </p>
  
  <p>My question is how do I get that token from the @decorated function? For example, lets say I have something like this:</p>
  
  <pre><code>@app.route(/token/)
  def getToken(code): #code from the callback url.
      #/Stuff to get the Token/
      #/**********************/
      return token
  </code></pre>
  
  <p>If I hit the (/token/) url-path the function returns the token. But now I need to get that token and use it in another function to write and read from the API I just got the token from. My initial thought was doing this:</p>
  
  <pre><code>token = getToken(code)
  </code></pre>
  
  <p>But if I do that, I get this error: </p>
  
  <pre><code>RuntimeError: working outside of request context
  </code></pre>
  
  <p>So again, my question is, how do I get the token so I can pass it as a parameter to other functions.</p>