- Author:
 - benjy_mouse
 - Posted:
 - February 13, 2010
 - Language:
 - Python
 - Version:
 - 1.1
 - Score:
 - 3 (after 3 ratings)
 
A simple template tag that returns the favicon URL for a given arbitrary URL.
Put the code into a python module in the templatetags package of a Django app (e.g. myapp/templatetags/mytags.py), and use it like this:
{% load mytags %}
...
<img src="{% favicon posting.url %}/>
<a href="{{ posting.url }}">{{posting.title}}</a>
...
1 2 3 4 5 6 7 8 9 10 11 12  | from django import template
from urlparse import urlparse, urlunparse
register = template.Library()
@register.simple_tag
def favicon(url):
    parsed_url = urlparse(url)
    return urlunparse((parsed_url[0], parsed_url[1],
                       u'favicon.ico', parsed_url[3],
                       parsed_url[4], parsed_url[5]))
 | 
More like this
- Add Toggle Switch Widget to Django Forms by OgliariNatan 1 month, 4 weeks ago
 - get_object_or_none by azwdevops 5 months, 2 weeks ago
 - Mask sensitive data from logger by agusmakmun 7 months, 2 weeks ago
 - Template tag - list punctuation for a list of items by shapiromatron 1 year, 9 months ago
 - JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 1 year, 9 months ago
 
Comments
Please login first before commenting.