title: NameError: name 'app' is not defined with Flask
body: <p>I have the following <em>structure</em> in my project</p>
  
  <pre><code>\ myapp
      \ app
         __init__.py
         views.py
      run.py
  </code></pre>
  
  <p>And the following code:</p>
  
  <p><strong>run.py</strong></p>
  
  <pre><code>from app import create_app
  
  if __name__ == '__main__':
      app = create_app()
      app.run(debug=True, host='0.0.0.0', port=5001)
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>@app.route("/")
  def index():
      return "Hello World!"
  </code></pre>
  
  <p><strong>_<em>init</em>_.py</strong></p>
  
  <pre><code>from flask import Flask
  
  
  def create_app():
      app = Flask(__name__)
      from app import views
      return app
  </code></pre>
  
  <p>I'm trying to use the <code>factory design pattern</code> to create my <code>app</code> objects with different <code>config</code> files each time, and with a subdomain dispatcher be able to create and route different objects depending on the <code>subdomain</code> on the user request.</p>
  
  <p>I'm following the Flask documentation where they talk about, all of this:</p>
  
  <ul>
  <li><a href="http://flask.pocoo.org/docs/appcontext/" rel="nofollow">Application Context</a></li>
  <li><a href="http://flask.pocoo.org/docs/patterns/appfactories/" rel="nofollow">Applitation Factories</a></li>
  <li><a href="http://flask.pocoo.org/docs/blueprints/#blueprints" rel="nofollow">Application with Blueprints</a></li>
  <li><a href="http://flask.pocoo.org/docs/patterns/appdispatch/" rel="nofollow">Application Dispatching</a></li>
  </ul>
  
  <p>But I couldn't make it work, it seems that with my actual project <code>structure</code> there are no way to pass throw the <code>app</code> object to my <code>views.py</code> and it throw and <code>NameError</code></p>
  
  <blockquote>
    <p>NameError: name 'app' is not defined</p>
  </blockquote>