25👍
✅
You can do it yourself
from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()
@register.filter
@stringfilter
def trim(value):
return value.strip()
91👍
Django templates allow you to access methods and properties by using the ‘.’ syntax:
{{ var.example.strip }}
You can extend this by chaining other filters when you’re dealing with HTML, e.g.:
{{ var.example.strip|safe|removetags:"p img" }}
Here we first remove any <p>
and <img>
tags, then tell Django it can safely render the rest of the content, which we have stripped of any whitespace.
- [Django]-Django 1.9: Field clashes with the field of non-existing field in parent model
- [Django]-Race conditions in django
- [Django]-Django 1.9 ImportError for import_module
Source:stackexchange.com