title: Flask app.add_url_rule in decorator error
body: <p>I have a bunch of decorators in my Flask routes that I am trying to condense into one (including <code>@app.route</code>).</p>
  
  <p>I have the following <code>@route</code> function:</p>
  
  <pre><code>from functools import wraps
  def route(route, method):
      def decorator(f):
          print 'decorator defined'
          print 'defining route'
          app.add_url_rule(route, methods=method, view_func=f)
          print 'route defined'
          @wraps(f)
          def wrapper(*args, **kwargs):
              print 'Hello'
              # do stuff here such as authenticate, authorise, check request json/arguments etc.
              # these will get passed along with the route and method arguments above.
              return f(*args, **kwargs)
          return wrapper
      return decorator
  </code></pre>
  
  <p>and a sample route:</p>
  
  <pre><code>@route('/status', ['GET'])
  def status():
      return Response('hi', content_type='text/plain')
  </code></pre>
  
  <p>The route is getting defined, but <code>wrapper()</code> never gets called, which is really odd. When I move <code>app.add_url_rule</code> outside of the decorator to the end of the file, then <code>wrapper()</code> gets called; so <code>decorator defined</code> statement prints on Flask startup, and <code>Hello</code> prints when I hit the <code>GET /status</code> route as expected.</p>
  
  <p>However, when I put <code>app.add_url_rule</code> back into the decorator as shown above, <code>decorator defined</code> prints on startup but when I call <code>GET /status</code>, it does not print <code>Hello</code> as if <code>app.add_url_rule</code> overrides the <code>wrapper()</code> function that I defined somehow.</p>
  
  <p>Why does this happen? It looks like <code>app.add_url_route</code> hijacks my function in some odd/unexpected way.</p>
  
  <p>How can I get <code>wrapper()</code> to be called once the route is hit, while defining <code>app.add_url_rule</code> in the decorator?</p>