I am looking for a django setting or programmatic way to make all django template tags show the empty string when the value is None. For example, imagine that I have some django
This should do the trick, put it somewhere in the initialization code, for eg. in wsgi.py
# Patch template Variable to output empty string for None values
from django.template.base import Variable
_resolve_lookup = Variable._resolve_lookup
def new_resolve_lookup(self, *args, **kwargs):
o = _resolve_lookup(self, *args, **kwargs)
return o or u""
Variable._resolve_lookup = new_resolve_lookup