Django template tag to truncate text

前端 未结 9 1811
长情又很酷
长情又很酷 2020-12-12 18:40

Django has truncatewords template tag, which cuts the text at the given word count. But there is nothing like truncatechars.

What\'s the best w

9条回答
  •  执念已碎
    2020-12-12 19:08

    You should write a custom template filter: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters

    Have a look at how truncatewords is built in django.utils.text

提交回复
热议问题