title: Flask.url_for() error: Attempted to generate a URL without the application context being pushed
body: <p>I have a trivial app where I'm trying to redirect the favicon per:</p>
  
  <p><a href="http://flask.pocoo.org/docs/0.10/patterns/favicon/" rel="noreferrer">http://flask.pocoo.org/docs/0.10/patterns/favicon/</a></p>
  
  <pre><code>app = flask.Flask(__name__)
  app.add_url_rule('/favicon.ico', redirect_to=flask.url_for('static', filename='favicon.ico'))
  </code></pre>
  
  <p>But this fails with:</p>
  
  <pre><code>RuntimeError: Attempted to generate a URL without the application context being pushed. This has to be executed when application context is available.
  </code></pre>
  
  <p>So, guessing, I try this:</p>
  
  <pre><code>app = flask.Flask(__name__)
  with app.app_context():
      flask.current_app.add_url_rule('/favicon.ico', redirect_to=flask.url_for('static', filename='favicon.ico'))
  </code></pre>
  
  <p>But get a different error:</p>
  
  <pre><code>RuntimeError: Application was not able to create a URL adapter for request independent URL generation. You might be able to fix this by setting the SERVER_NAME config variable.
  </code></pre>
  
  <p>What is going on?</p>