How do you send a function from a view to a Jinja2 template?

47 views
Skip to first unread message

Rosciuc Bogdan

unread,
Nov 16, 2014, 1:37:15 PM11/16/14
to pylons-...@googlegroups.com
Hello all,

Pretty much what the title says. I've been trying to send a function I have created in a view to a Jinja2 template and I can't figure it out how. Could you please help me with this... an example may be useful as well.

Thank you,
Bogdan

Michael Merickel

unread,
Nov 16, 2014, 4:40:15 PM11/16/14
to Pylons
You send a function just like any other object. By returning it as the
value in a dictionary.

python:
def hello_fn(name):
return 'Hello ' + name

return {
'hello': hello_fn,
}

jinja2:
{{ hello('bob') }}

- Michael
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pylons-discus...@googlegroups.com.
> To post to this group, send email to pylons-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Rosciuc Bogdan

unread,
Nov 17, 2014, 6:23:30 AM11/17/14
to pylons-...@googlegroups.com
Thaks a lot. I've been using a different method (declaring the view as a class) but I will give this one a try as well as it seems less 'complicated'.

Regards,
Bogdan
Reply all
Reply to author
Forward
0 new messages