Limit number of characters with Django Template filter

后端 未结 6 1168
盖世英雄少女心
盖世英雄少女心 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:24

    Using a templatefilter for truncating your text isn't really suitable for a responsive design. Therefore you could also use css to truncate your text that is responsive. I know the OP asked to do this with a django templatefilter.

    You can achieve a responsive truncated text using this:

    .class {
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    

提交回复
热议问题