From a3f78af87019bfd89063cf5bc0c19f27325f36c1 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Fri, 13 Aug 2010 23:37:57 +0200 Subject: [PATCH] Improved the templated decorator in the documentation as recommended by Thadeus Burgess on the mailinglist --- docs/patterns/viewdecorators.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/patterns/viewdecorators.rst b/docs/patterns/viewdecorators.rst index 49620ff8..73d67852 100644 --- a/docs/patterns/viewdecorators.rst +++ b/docs/patterns/viewdecorators.rst @@ -120,7 +120,9 @@ As you can see, if no template name is provided it will use the endpoint of the URL map with dots converted to slashes + ``'.html'``. Otherwise the provided template name is used. When the decorated function returns, the dictionary returned is passed to the template rendering function. If -`None` is returned, an empty dictionary is assumed. +`None` is returned, an empty dictionary is assumed, if something else than +a dictionary is returned we return it from the function unchanged. That +way you can still use the redirect function or return simple strings. Here the code for that decorator:: @@ -138,6 +140,8 @@ Here the code for that decorator:: ctx = f(*args, **kwargs) if ctx is None: ctx = {} + elif not isinstance(ctx, dict): + return ctx return render_template(template_name, **ctx) return decorated_function return decorator