4

I want to create meta description on my website, in this moment i have this function for get product description :

{{ product.description|nl2br }}                                 

Need edit this function for get only the first 150 characters for create meta description, is possible this in template ? or need create this function in views.py ?

r-m-n
  • 14,192
  • 4
  • 69
  • 68
selfmarket.net
  • 139
  • 1
  • 2
  • 7

1 Answers1

13

jinja2 has a filter named truncate, the documentation is here:

{{ "foo bar baz"|truncate(9) }}
-> "foo ..."

so, you can try this one:

{{ product.description | truncate(150) }}    
lord63. j
  • 4,500
  • 2
  • 22
  • 30