Flask context missing in 404 errorhandler
<p>I have the following structure for my flask application. When an invalid url comes in a 404 error is called, but my 404.html requires data from the context_processor but in the abort 404 the blueprint is None so context_processor is never called and 404.html is missing data.</p>

<p>How can I approach this differently?</p>

<h3><strong>init</strong>.py</h3>

<pre><code>def create_app(settings_overide=None):
    app = factory.create_app(__name__, __path__, settings_overide)
    if not app.debug:
        app.errorhandler(404)(page_not_found)

    return app

def page_not_found(e):
    return render_template('404.html'), 404
</code></pre>

<h3>processors.py</h3>

<pre><code>@blueprint.context_processor
def load_global_data():
    return get_data()
</code></pre>

<p>When a route is not found, no blueprint is set yet (because setting a blueprint requires a route to be determined first). As such a 404 error handler can't count on a blueprint to have been determined.</p>

<p>You'd have to execute the <code>get_data()</code> call manually. Test if a specific global has been set, then execute the <code>get_data()</code> function if not before rendering your 404 template.</p>

python flask