3

If I use

{{ post.body_html | safe }}

program will select data from MySQL and display on browser as complete article. So does jinja2 have filter help show part of variable like article's first paragraph.

大易归真
  • 545
  • 1
  • 5
  • 15

1 Answers1

11

You can use the truncate() filter. You can send to it as argument the number of characters you want to show in your template:

{{ post.body_html | truncate(40) | safe }}

Obviously you can code a function (in your python file) which detects the first paragraph, counts the number of characters and send this number (that it returns) to your truncate() filter in your template.

doru
  • 9,022
  • 2
  • 33
  • 43