What does "local to a blueprint" mean?
<p>I'm having some trouble understanding the difference between <a href="http://flask.pocoo.org/docs/0.10/api/#flask.Blueprint.errorhandler" rel="nofollow">Blueprint.errorhandler</a> and <a href="http://flask.pocoo.org/docs/0.10/api/#flask.Blueprint.app_errorhandler" rel="nofollow">Blueprint.app_errorhandler</a>. According the API document(emphasis mine):</p>

<blockquote>
  <p><code>errorhandler(code_or_exception)</code></p>
  
  <p>Registers an error handler that becomes active for this blueprint
  only. Please be aware that routing does not happen <strong>local to a
  blueprint</strong> so an error handler for 404 usually is not handled by a
  blueprint unless it is caused inside a view function. Another special
  case is the 500 internal server error which is always looked up from
  the application.</p>
</blockquote>

<p>AFAIK, a blueprint object in Flask is "a set of operations which can be registered on an application, even multiple times".</p>

<p>My questions are:</p>

<ol>
<li>How can an error be local to a set of operations?</li>
<li>How can a view function cause an error?</li>
</ol>

<p>'local' means that in relation to the routes a blueprint registers. Blueprint routes are always prefixed by the name you registered your blueprint with, so they are naturally grouped and in a URL path topology sense they have locality. 'nonlocal' then is any view not associated with the blueprint; they'll have a different prefix or no prefix at all.</p>

<p>View functions can raise <a href="https://docs.python.org/2/library/exceptions.html" rel="nofollow"><em>exceptions</em></a>, and specific exceptions (anything derived from <a href="http://werkzeug.pocoo.org/docs/0.11/exceptions/#werkzeug.exceptions.HTTPException" rel="nofollow"><code>HTTPException</code></a>) have a HTTP error code associated with them. <code>@blueprint.errorhandler()</code> registers a handler for such exceptions or associated HTTP error codes.</p>

<p>What the documentation is stating is that errors raised <em>during routing</em> (such as the 404 <code>NotFound</code> error) do not have a view yet and therefor you can't route that error to a specific blueprint either.</p>

<p>Under the hood, when routing succeeds to find a view to handle the request, <code>request.blueprint</code> is set to the associated registered blueprint that corresponds to that view. If then an error occurs and an error handler needs to be found, the <code>request.blueprint</code> value lets Flask find 'local' error handlers.</p>

python flask error-handling decorator