I want to write a custom function and pass it unto my tornado template fine.
Like def trimString(data): return data[0:20] then push this into my tornado file.
This should allow me trim strings.
Is this possible?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s not especially clear in the documentation, but you can do this easily by defining this function in a module and passing the module to
tornado.web.Applicationas theui_methodsargument.I. E.:
in ui_methods.py:
in app.py:
in main.html:
Andy Boot’s solution also works, but it’s often nice to have functions like this automatically accessible in every template.