Creating a custom context processor
Sometimes, we might want to calculate or process a value directly in templates. Jinja maintains the notion that the processing of logic should be handled in views and not in templates, thereby keeping templates clean. A context processor becomes a handy tool in this case. With a context processor, we can pass our values to a method, which will then be processed in a Python method, and our resultant value will be returned. This is done by simply adding a function to the template context, thanks to Python allowing its users to pass functions like any other object. In this recipe, we’ll see how to write a custom context processor.
How to do it...
To write a custom context processor, follow the steps described as follows.
Let’s first display the descriptive name of the product in the Category / Product-name
format. Afterward, add the method to my_app/product/views.py
, as follows:
@product_blueprint.context_processor def some_processor...