In my app teams/templatetags/teams_extras.py I have this filter
from django import template
register = template.Library()
@register.filter(is_safe=True)
def quote(text):
return "« {} »".format(text)
So I use it into my view teams/templates/teams/show.html
{% extends './base.html' %}
{% load static %}
{% load teams_extras %}
...
<b>Bio :</b> {{ team.biography|quote }}
...
But this is the result on my page:
« <p>The Miami Heat are an American professional basketball team based in Miami. The Heat compete in the National Basketball Association as a member of the league's Eastern Conference Southeast Division</p> »
Why ? Thank you
Doc says:
This flag tells Django that if a “safe” string is passed into your filter, the result will still be “safe” and if a non-safe string is passed in, Django will automatically escape it, if necessary.
So try to pass safe value into your filter:
{{ team.biography|safe|quote }}
or user mark_safe:
from django.utils.safestring import mark_safe
@register.filter()
def quote(text):
return mark_safe("« {} »".format(text))
And:
{{ team.biography|quote }}
This should works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With