title: Adding a custom filter to jinja2 under pyramid
body: <p>This question has been asked <a href="https://stackoverflow.com/questions/8339899/jinja2-custom-filter-templateassertionerror-no-filter-named-format-number">before</a> but the accepted solution (given by the question poster himself) says that we can add the new filter to jinja2.filter.FILTER straightaway.</p>
  
  <p>But in the <a href="http://jinja.pocoo.org/docs/api/#custom-filters" rel="nofollow noreferrer">jinja2 documentation</a>, it is advised that the filter be added to the environment.</p>
  
  <p>I am developing an app under pyramid and need to define my custom filter and do the following.</p>
  
  <pre><code>from jinja2 import Environment
  
  #Define a new filter
  def GetBitValue(num,place):
      y = (num &gt;&gt; (place-1)) &amp; 1
      return y
  
  env = Environment()
  env.filters['getbitvalue'] = GetBitValue
  </code></pre>
  
  <p>Where should this code fragment be placed? </p>
  
  <p>I tried placing it in the views file but that obviously did not work. </p>
  
  <p>If i place it in <code>__init__.py</code>, how do I make sure that jinja2 picks it up? I mean how do I send back the <code>env</code> to jinja2 settings under pyramid?</p>