Suppose I want to override a Jinja macro with a function defined in routes.py
that returns None
. I attempted to use a Context Processor (@app.context_processor
) but it didn’t override the macro. (It outputs the assignment made in macros.html
.)
routes.py
@app.context_processor
def thing():
def my_macro():
return None
return dict(my_macro=my_macro)
macros.html
{% macro my_macro() %}Arbitrary_text{% endmacro %}
The reason I am doing this is so I can add some conditional datetime logic using python (instead of writing it in Jinja).
Context Processor documentation is here: https://flask.palletsprojects.com/en/2.2.x/templating/#context-processors