1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # template tags file
import re
from django import template
register = template.Library()
@register.filter(name='twitterize')
def twitterize(token):
return re.sub(r'\W(@(\w+))', r'<a href="https://twitter.com/\2">\1</a>', token)
twitterize.is_safe = True
# Use in your templates like this:
<ul>
{% for t in tweets %}
<li>{{ t.text|urlize|twitterize }}</li>
{% endfor %}
</ul>
|
More like this
- Template range filter by zalun 4 years, 2 months ago
- isoutc template filter by japerk 4 years, 1 month ago
- Template filter to convert timecodes into links by justin_h 3 years, 8 months ago
- "Partial Templates" - an alternative to "include" by vigrid 4 years, 3 months ago
- Template tag to clear cached template fragment by joao.coelho 3 years, 6 months ago
Comments