Create a gist now

Instantly share code, notes, and snippets.

twittify: django template filter to replace metions (@'s) and hashtags (#'s) with links to twitter
def twittify(value):
""" Replace @ and #'s with links to twitter"""
return mark_safe(
re.sub(r"#(?P<ht>([a-zA-Z0-9_])+)", r"#<a href='!/search?q=\g<ht>' target='_blank'>\g<ht></a>",
re.sub(r"@(?P<un>([a-zA-Z0-9_]){1,15})", r"@<a href='\g<un>' target='_blank'>\g<un></a>", value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment