Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8733665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:41:51+00:00 2026-06-13T09:41:51+00:00

I want to write a custom function and pass it unto my tornado template

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:41:53+00:00Added an answer on June 13, 2026 at 9:41 am

    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.Application as the ui_methods argument.

    I. E.:

    in ui_methods.py:

    def trim_string(data):
        return data[0:20]
    

    in app.py:

    import tornado.ioloop
    import tornado.web
    
    import ui_methods
    
    class MainHandler(tornado.web.RequestHandler):
        def get(self):
            self.render("main.html")
    
    
    urls = [(r"/", MainHandler)]
    application = tornado.web.Application(urls, ui_methods=ui_methods)
    
    if __name__ == "__main__":
        application.listen(8888)
        tornado.ioloop.IOLoop.instance().start()
    

    in main.html:

    ....
    {{ trim_string('a string that is too long............') }}
    ....
    

    Andy Boot’s solution also works, but it’s often nice to have functions like this automatically accessible in every template.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large data set and I want to write a custom merge
I want to write a custom next/prev function to dynamically display post information in
Question: I want to write a custom aggregate function that concatenates string on group
I want to write a custom class that behaves like dict - so, I
I want to write a custom validator which doesn't do anything before the user
I want write a simple query which will fetch data from a table (which
I'm attempting to write my first custom Cocoa Framework and I want to expose
I want to write a function such that when class clipartcategory clicked above of
I am attempting to write a custom control. I want to allow its user
Basically, i want to write a windows form program like any other webcam's control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.