How to define global template variables in Flask

Let’s say you want to have some variables available in all templates by default. There’s how you do it:

@app.context_processor
    def inject_global_vars():
        return {'x': 1}

Now x is available everywhere. You can see it in action here

Leave a Comment

Your email address will not be published. Required fields are marked *