def getlinks(value):
try:
import beautifulsoup
except ImportError:
if settings.DEBUG:
raise template.TemplateSyntaxError, "Error in {% getlinks %} filter: The Python BeautifulSoup and/or urllib2 libraries aren't installed."
return value
else:
soup = beautifulsoup.BeautifulSoup(value)
return soup.findAll('a')
"""
Returns links found in an (X)HTML string as Python objects for itteration in templates.
EXAMPLE:
<ul>
{% for link in blog.entry.body|getlinks %}
<li><a href="{{ link.href }}">{{ link.title }}</a></li>
{% endfor %}
</ul>
"""
Comments
Aah, wonderful - I always wondered how you did this!
#
Thanks. I just wondered how to implement this.
#
Separately* ^-^
Also, someone posted a duplicate.
#