[Fixed]-Can I cut out the string in the Django template?

26👍

You can use slice filter:

<li><a href="/article_list_content-{{win_con.id}}/"><p>{{ win_con.content|slice:":5" }}</p><i class="font">&#xe6aa;</i></a></li>

13👍

you may use built-in filter truncatechars

{{ win_con.content|truncatechars:5 }}

3👍

0👍

To cut specific characters do you could use ‘cut’ which is also part of django template builtins

for example if

{{ file.pdf.name}}

gives ‘store/pdfs/verma2010.pdf’

{{ file.pdf.name | cut:'store/pdfs/'}}

Would give ‘verma2010.pdf’

Leave a comment