I get the text from the database. In the template, I need to display a list, each element of which is a separate line (in the sense, the text should be split by '\ n'). The question is how can this be implemented?

1 answer 1

In the templatetags folder create files new_tags.py and __init__.py . Content new_tags.py :

from django import template register = template.Library() @register.filter(name='split') def split(value, splitter): return value.split(splitter) 

In the template:

 {% load new_tags %} <ul> {% for item in text|split:"\n" %} <li>{{ item }}</li> {% endfor %} </ul> 

For more information about your template tags: https://docs.djangoproject.com/en/2.0/howto/custom-template-tags/