Loading docs/howto/custom-template-tags.txt +5 −3 Original line number Diff line number Diff line Loading @@ -88,9 +88,11 @@ Custom filters are just Python functions that take one or two arguments: For example, in the filter ``{{ var|foo:"bar" }}``, the filter ``foo`` would be passed the variable ``var`` and the argument ``"bar"``. Filter functions should always return something. They shouldn't raise exceptions. They should fail silently. In case of error, they should return either the original input or an empty string -- whichever makes more sense. Usually any exception raised from a template filter will be exposed as a server error. Thus, filter functions should avoid raising exceptions if there is a reasonable fallback value to return. In case of input that represents a clear bug in a template, raising an exception may still be better than silent failure which hides the bug. Here's an example filter definition: Loading Loading
docs/howto/custom-template-tags.txt +5 −3 Original line number Diff line number Diff line Loading @@ -88,9 +88,11 @@ Custom filters are just Python functions that take one or two arguments: For example, in the filter ``{{ var|foo:"bar" }}``, the filter ``foo`` would be passed the variable ``var`` and the argument ``"bar"``. Filter functions should always return something. They shouldn't raise exceptions. They should fail silently. In case of error, they should return either the original input or an empty string -- whichever makes more sense. Usually any exception raised from a template filter will be exposed as a server error. Thus, filter functions should avoid raising exceptions if there is a reasonable fallback value to return. In case of input that represents a clear bug in a template, raising an exception may still be better than silent failure which hides the bug. Here's an example filter definition: Loading