Yes, you can override the finalize method or patch it on the environment:
def silent_none(value):
if value is None:
return ''
return value
from jinja2 import Environment
env = Environment()
env.finalize = silent_none
I however recommend being explicit instead of a finalizer:
{{ variable or '' }}
Regards,
Armin
Hi,Yes, you can override the finalize method or patch it on the environment:
On 2010-09-19 2:21 AM, kevin wrote:
if a variable is None, the text 'None' gets output/printed in the html.
is possible to have empty string instead of 'None'?
thanks
def silent_none(value):
if value is None:
return ''
return value
from jinja2 import Environment
env = Environment()
env.finalize = silent_none
I however recommend being explicit instead of a finalizer:
{{ variable or '' }}