Merge branch 'master' into module-support

This commit is contained in:
Armin Ronacher 2010-04-25 14:54:33 +02:00
commit 36e24299e3
3 changed files with 59 additions and 0 deletions

View file

@ -12,6 +12,7 @@
from __future__ import with_statement
import os
import sys
import types
from itertools import chain
from jinja2 import Environment, PackageLoader, FileSystemLoader
@ -825,6 +826,23 @@ class Flask(_PackageBoundObject):
return f
return decorator
def template_filter(self, name=None):
"""A decorator that is used to register custom template filter.
You can specify a name for the filter, otherwise the function
name will be used. Example::
@app.template_filter()
def reverse(s):
return s[::-1]
:param name: the optional name of the filter, otherwise the
function name will be used.
"""
def decorator(f):
self.jinja_env.filters[name or f.__name__] = f
return f
return decorator
def before_request(self, f):
"""Registers a function to run before each request."""
self.before_request_funcs.setdefault(None, []).append(f)