|
|
@ -12,6 +12,7 @@ |
|
|
|
from __future__ import with_statement |
|
|
|
from __future__ import with_statement |
|
|
|
import os |
|
|
|
import os |
|
|
|
import sys |
|
|
|
import sys |
|
|
|
|
|
|
|
import types |
|
|
|
|
|
|
|
|
|
|
|
from jinja2 import Environment, PackageLoader, FileSystemLoader |
|
|
|
from jinja2 import Environment, PackageLoader, FileSystemLoader |
|
|
|
from werkzeug import Request as RequestBase, Response as ResponseBase, \ |
|
|
|
from werkzeug import Request as RequestBase, Response as ResponseBase, \ |
|
|
@ -639,6 +640,27 @@ class Flask(object): |
|
|
|
return f |
|
|
|
return f |
|
|
|
return decorator |
|
|
|
return decorator |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def template_filter(self, arg=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. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
if type(arg) is types.FunctionType: |
|
|
|
|
|
|
|
self.jinja_env.filters[arg.__name__] = arg |
|
|
|
|
|
|
|
return arg |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def decorator(f): |
|
|
|
|
|
|
|
self.jinja_env.filters[arg or f.__name__] = f |
|
|
|
|
|
|
|
return f |
|
|
|
|
|
|
|
return decorator |
|
|
|
|
|
|
|
|
|
|
|
def before_request(self, f): |
|
|
|
def before_request(self, f): |
|
|
|
"""Registers a function to run before each request.""" |
|
|
|
"""Registers a function to run before each request.""" |
|
|
|
self.before_request_funcs.append(f) |
|
|
|
self.before_request_funcs.append(f) |
|
|
|