title: Flask-Script How to get to the current app?
body: <p>I'm trying to get access to the current app instance from a Flask-Script manager.command.  </p>
  
  <p>This errors out (url_map is a property of flask.app)</p>
  
  <pre><code>@manager.command
  def my_function():
      x = app.url_map # this fails, because app is a callable
      print "hi"
  </code></pre>
  
  <p>This works, but I don't like having to add parens next to app.</p>
  
  <pre><code>@manager.command
  def my_function():
      x = app().url_map
      print "hi"
  </code></pre>
  
  <p>The debugger shows that app is a callable.  That has to do with the way that I'm creating the app instance.  I'm following this pattern:</p>
  
  <pre><code>def create_app(settings=None, app_name=None, blueprints=None):
      ...lots of stuff...
      app = flask.Flask(app_name)
      ...lots of stuff...
      return app
  
  
  def create_manager(app):
      manager = Manager(app)
  
  
      @manager.command
      def my_function():
          x = app.url_map
          print "hi"
  
  
  def main():
      manager = create_manager(create_app)
      manager.run()
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>The <a href="http://flask-script.readthedocs.org/en/latest/" rel="nofollow">docs from flask-script</a> say about the app parameters on <code>Manager(app)</code>: </p>
  
  <blockquote>
    <p>app – Flask instance, or callable returning a Flask instance.</p>
  </blockquote>
  
  <p>I'm comfortable with putting a callable in there because the docs say it's OK.  :-)  Plus I've seen others do it like that.  </p>
  
  <p>But now I have this peripheral command that I'd like to add and it's forcing me to use the app with parens and that smells wrong.  What am I doing wrong?</p>
  
  <p><strong>EDIT</strong>: I did some experiments.  This is definitely wrong.  By adding the parens, the app instance is getting recreated a second time.  </p>