Limit number of characters with Django Template filter

后端 未结 6 1086
盖世英雄少女心
盖世英雄少女心 2021-02-01 12:34

I am trying to output the first 255 characters of a description on a list of items and am looking for a method to get that.

Example: I have a variable that contains 300

6条回答
  •  别那么骄傲
    2021-02-01 13:03

    A more simple way by using the standard template tag is:

    {{ variable|stringformat:".10s" }}
    

    In this case the 10 is the position argument and for a string it is the maximum number of characters to be displayed.

提交回复
热议问题