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?
- 3A possible duplicate of the question: How to make, that the lines would be transferred when generating from the template as they were entered into the textarea? - Sergey Gornostaev
|
1 answer
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/
|