title: How are decorators tied to a Flask application instances?
body: <p>My situation is that I want to ran a Flask application with Apache2 and currently if I do as any Flask tutorial says everything works just fine. My problem is that I don't understand how decorators, namely routers, are tied to a Flask application and none of the tutorials nor the Flask's own documentation is of any use in this regard. I've tried my best to find information regarding how decorators, namely routers, are tied to a Flask application instance but I've come up with nothing. At the moment how everything "just works" and this all seems like witchcraft to me.</p>
  
  <p>Namely, my initial application is something like this:</p>
  
  <pre><code>myproject/
      app/
        __init__.py
        routes.py
      myproject.wsgi
  </code></pre>
  
  <p>where <code>__init__.py</code> has the following content:</p>
  
  <pre><code>from flask import Flask
  app = Flask(__name__)
  from app import routes
  </code></pre>
  
  <p><code>routes.py</code> has the following content:</p>
  
  <pre><code>from app import app
  @app.route('/')
  @app.route('/index')
  def index():
      return 'Hello, World!'
  </code></pre>
  
  <p>and <code>myproject.wsgi</code> has the following content:</p>
  
  <pre><code>import sys
  sys.path.insert(0, '/var/www/test')
  from app import app as application
  </code></pre>
  
  <p>Now, my application has grown a bit and I would like to implement properly working unit tests for it. My <code>tests</code> folder is in the same root directory as the <code>myproject</code>.</p>
  
  <p>What is unclear to me is that when I import the <code>app</code> from the <code>myproject</code> for testing, does it automatically have the functionality assigned to it from the decorators in <code>routes.py</code>? If so, why and how does this work? If not, how do I test the functions I assign to an application with decorators? The latter is probably only important when I need to test <code>POST</code> requests.</p>
  
  <p>Also, could someone tell me why almost in every Flask tutorial the application, namely the <code>app</code> is build in the <code>__init__.py</code> file of the project? Wouldn't it be easier to initialize it for example in <code>app.py</code> file or something similar?</p>
  
  <p>I've tried my best to find information regarding how decorators, namely routers, are tied to a Flask application instance but I've come up with nothing. At the moment how everything "just works" in Flask seems like witchcraft as in every single </p>