Method: flask.app.Flask.template_test
Calls: 4, Exceptions: 0, Paths: 1Back
Path 1: 4 calls (1.0)
None (2) 'boolean' (2)
Flask.template_test.
1@setupmethod
2 def template_test(
3 self, name: str | None = None
4 ) -> t.Callable[[T_template_test], T_template_test]:
5 """A decorator that is used to register custom template test.
6 You can specify a name for the test, otherwise the function
7 name will be used. Example::
8
9 @app.template_test()
10 def is_prime(n):
11 if n == 2:
12 return True
13 for i in range(2, int(math.ceil(math.sqrt(n))) + 1):
14 if n % i == 0:
15 return False
16 return True
17
18 .. versionadded:: 0.10
19
20 :param name: the optional name of the test, otherwise the
21 function name will be used.
22 """
23
24 def decorator(f: T_template_test) -> T_template_test:
25 self.add_template_test(f, name=name)
26 return f
27
28 return decorator