2014-04-21 16 views
0

如何根據字數統計字數來截斷文本字段?按總字數統計的百分比截斷字

例如{{ post.content|truncatewords_by_percents:"20%" }}

+0

檢查是否有一個內置的模板標籤,https://docs.djangoproject.com/en/dev/ref/templates/builtins/, 如果沒有,你可以創建自己的模板標籤HTTPS ://docs.djangoproject.com/en/dev/howto/custom-template-tags/ – dm03514

回答

1

不可能不進行自定義的模板標籤。內置的模板標籤只允許通過字符或單詞進行截斷。請參閱文檔here。看到