Specify the lines of textfield to display
Specify the lines of textfield to display I want to make a preview of my article. How to select first several lines of TextField ? I am using the flask and wtforms. TextField class Blog(Model): content = TextField() template: {{blog.content}} But how to specify the first several lines to display? For example, only display 4 lines. blog.content(rows = 4) blog.content(rows = 4) 1 Answer 1 If blog.content consists of lines separated by newline characters, you can just split the content by newline and return the first four elements, joined: blog.content >>> content = 'OnenTwonThreenFournFivenSix' >>> parts = content.split('n') >>> preview = 'n'.join(parts[:4]) >>> preview # use this in the template {{ preview }} 'OnenTwonThreenFour' If blog.content does not consist of lines separated by newline characters, you could use jinj...