I'm using |escape filter ...so a question is :
Is there is some method to enable global escape filter ? :)
I've been thinking about this recently, and I've come to the
conclusion that we might have missed a trick by not making ALL
replacement variables escaped by default (and including a var|raw
filter for the times when you don't want stuff to be escaped). It's
probably too late to change this now though.
One solution is to write your own custom Context class and use that.
The following code is unteste:
from django.template.context import Context
from django.utils.html import escape
class EscapedContext(Context):
def __getitem__(self, key):
value = super(Context, self)[key]
return escape(value)
You would also need to add your own 'unescape' custom template filter
that reverses the effects of escape for cases where you needed to do
that. Maybe unescape would be a useful addition to the default set of
template tags...
Cheers,
Simon
I thought we'd kind of reached consensus this (always escape) was a good
idea last time this came up. But then it slipped into the "too hard for
now" basket.
Anyway, Simon no doubt remembers the arguments (since he was involved),
but for others wanting to see past discussions, here are two threads
that provide some background of ideas...
Regards,
Malcolm