Skip to content
Myr

Added module support to templated decorator.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent eeb0e94 · Browse files · 1 file+6 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−5 removed

  • other:+6 added−5 removed

1 file+6 added−5 removed

modified:docs/patterns/viewdecorators.rst+6 added-5 removed
115 unmodified lines
116 def index():117 return dict(value=42)118119As you can see, if no template name is provided it will use the endpoint120of the URL map + ``'.html'``. Otherwise the provided template name is121used. When the decorated function returns, the dictionary returned is122passed to the template rendering function. If `None` is returned, an123empty dictionary is assumed.120of the URL map with dots converted to slashes + ``'.html'``. Otherwise121the provided template name is used. When the decorated function returns,122the dictionary returned is passed to the template rendering function. If123`None` is returned, an empty dictionary is assumed.124125Here the code for that decorator::126127 from functools import wraps
4 unmodified lines
132 @wraps(f)133 def decorated_function(*args, **kwargs):134 template_name = template135 if template_name is None:136 template_name = request.endpoint + '.html'136 template_name = request.endpoint \137 .replace('.', '/') + '.html'138 ctx = f(*args, **kwargs)139 if ctx is None:140 ctx = {}141 return render_template(template_name, **ctx)
2 unmodified lines