Minor edit to doc
- From:
- Thadeus Burgess
- Date:
- 2010-08-13 @ 21:26
I suggest a modified version of the templated decorator located in the docs.
Instead of always attempting to render_template on the ctx, only do
this if the ctx is a dictionary.
That way you can still do something like ``return redirect(...)`` if
you need to.
def templated(template=None):
def decorator(f):
@wraps(f)
def decorated_function(*args, **kwargs):
template_name = template
if template_name is None:
template_name = request.endpoint \
.replace('.', '/') + '.html'
ctx = f(*args, **kwargs)
if isinstance(ctx, dict):
return render_template(template_name, **ctx)
else:
return ctx
return decorated_function
return decorator
--
Thadeus
Re: [flask] Minor edit to doc
- From:
- Armin Ronacher
- Date:
- 2010-08-13 @ 21:39
Hi,
On 8/13/10 11:26 PM, Thadeus Burgess wrote:
> I suggest a modified version of the templated decorator located in the docs.
And changed :) Thanks for that.
Regards,
Armin