This question has been asked before , but the decision made (given by the author of the question) says that we can add a new filter to jinja2.filter.FILTER right now.
But in jinja2 documentation , it is recommended to add a filter to the environment.
I am developing an application under a pyramid and must define my custom filter and do the following.
from jinja2 import Environment
def GetBitValue(num,place):
y = (num >> (place-1)) & 1
return y
env = Environment()
env.filters['getbitvalue'] = GetBitValue
Where should this piece of code be placed?
I tried to put it in a views file, but that obviously didn't work.
If I put it in __init__.py, how can I make sure jinja2 picks it up? I mean, how do I send settings envto jinja2 under the pyramid?
source
share