10👍
✅
Define a custom filter, say mysplit
.
@register.filter
def mysplit(value, sep = "."):
parts = value.split(sep)
return (parts[0], sep.join(parts[1:]))
Then use the filter in your template:
{% with text|mysplit:"." as parts %}
<p class="highlight">{{ parts.0 }}</p>
<p class="normal">{{ parts.1 }}</p>
{% endwith %}
This was tested with Django 1.2.1.
Source:stackexchange.com