Kaydet (Commit) 0b43308e authored tarafından Carl Meyer's avatar Carl Meyer Kaydeden (comit) Tim Graham

[1.7.x] Fixed #22412 -- More nuanced advice re template filters and exceptions.

Thanks Tim for review.

Backport of 7e3834ad from master
üst 941f947b
...@@ -88,9 +88,11 @@ Custom filters are just Python functions that take one or two arguments: ...@@ -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 For example, in the filter ``{{ var|foo:"bar" }}``, the filter ``foo`` would be
passed the variable ``var`` and the argument ``"bar"``. passed the variable ``var`` and the argument ``"bar"``.
Filter functions should always return something. They shouldn't raise Usually any exception raised from a template filter will be exposed as a server
exceptions. They should fail silently. In case of error, they should return error. Thus, filter functions should avoid raising exceptions if there is a
either the original input or an empty string -- whichever makes more sense. 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: Here's an example filter definition:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment