Login

Template filter to turn Twitter names into links

Author:
mrben_
Posted:
July 14, 2010
Language:
Python
Version:
Not specified
Tags:
twitter twtterize
Score:
0 (after 0 ratings)

Quick and simple twitterize filter to turn Twitter usernames into profile links on your own sites.

Add the filter code to your own template tags (http://docs.djangoproject.com/en/dev/howto/custom-template-tags/).

 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

  1. Twitter template tags and filters by moxypark 4 years, 11 months ago
  2. Twitterfy by dougal 5 years, 10 months ago
  3. twitterize filter by thomasw 6 years, 3 months ago
  4. @reply links and hash tags in Twitter messages by dougal 6 years, 5 months ago
  5. @reply links in Twitter messages by ryanberg 7 years ago

Comments

Please login first before commenting.