28👍
✅
To disable autoescape you can use mark_safe
method:
from django.utils.safestring import mark_safe
@register.filter(is_safe=True)
def format_description(description):
text = ''
for i in description.split('\n'):
text += ('<p class="site-description">' + i + '</p>')
return mark_safe(text)
10👍
This is explicitly covered in the documentation: Filters and auto-escaping.
You need to mark the output as safe.
from django.utils.safestring import mark_safe
...
return mark_safe(text)
- Is it correct to modify old migration files in Django?
- 'CheckoutView' object has no attribute 'object'
- Django – inline – Search for existing record instead of adding a new one
Source:stackexchange.com