title: Using Flask Blueprints, how to fix url_for from breaking if a subdomain is specified?
body: <p>Inside of a flask blueprint, i have:</p>
  
  <pre><code>frontend = Blueprint('frontend', __name__)
  </code></pre>
  
  <p>and the route to my index function is:</p>
  
  <pre><code>@frontend.route('/')
  def index():
    #code
  </code></pre>
  
  <p>This works fine but, I am trying to add a subdomain to the route, like so:</p>
  
  <pre><code>@frontend.route('/', subdomain='&lt;var&gt;')
  def index(var):
  </code></pre>
  
  <p>But this breaks the app and the browser spits out (amongst other things):</p>
  
  <pre><code>werkzeug.routing.BuildError
  BuildError: ('frontend.index', {}, None)
  </code></pre>
  
  <p>frontend.index is called out in my code in a few places in a <em>url_for('frontend.index')</em></p>
  
  <p>How can I get the url_for to work when I'm including a subdomain? The only thing in the documents I can find and I think might be relevant is this under <a href="http://flask.pocoo.org/docs/api/" rel="noreferrer">http://flask.pocoo.org/docs/api/</a>:</p>
  
  <blockquote>
    <p>To integrate applications, Flask has a hook to intercept URL build
    errors through Flask.build_error_handler. The url_for function results
    in a BuildError when the current app does not have a URL for the given
    endpoint and values. When it does, the current_app calls its
    build_error_handler if it is not None, which can return a string to
    use as the result of url_for (instead of url_for‘s default to raise
    the BuildError exception) or re-raise the exception. An example:</p>
  </blockquote>
  
  <pre><code>def external_url_handler(error, endpoint, **values):
      "Looks up an external URL when `url_for` cannot build a URL."
      # This is an example of hooking the build_error_handler.
      # Here, lookup_url is some utility function you've built
      # which looks up the endpoint in some external URL registry.
      url = lookup_url(endpoint, **values)
      if url is None:
          # External lookup did not have a URL.
          # Re-raise the BuildError, in context of original traceback.
          exc_type, exc_value, tb = sys.exc_info()
          if exc_value is error:
              raise exc_type, exc_value, tb
          else:
              raise error
      # url_for will use this result, instead of raising BuildError.
      return url
  
  app.build_error_handler = external_url_handler
  </code></pre>
  
  <p>However, I am new to python (and programming) and can not understand where I would put this code or how I would get that function to call when a builderror occurs.</p>
  
  <p>Any insight would be greatly appreciated :)</p>