html helpers for images and links

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def link(url, text='', classes=''):
    if not text: text = url
    if classes: classes = ' class="%s"' % classes
    return """<a href="%s"%s>%s</a>""" % (url, classes, text)

def img(url, alt='', classes=''):
    if not url.startswith('http://') and not url[:1]=='/':
        #add media_url for relative paths
        import settings
        url = settings.MEDIA_URL + url
    if classes: classes = ' class="%s"' % classes
    if alt: alt = ' alt="%s" title="%s"' % (alt, alt)
    return """<img src="%s"%s%s>""" % (url, classes, alt)

More like this

  1. iPernity thumbnail helper by sedden 4 years, 6 months ago
  2. Class Feeds DRY TemplateTag by gmandx 3 years ago
  3. [UPDATE]Filter to resize a ImageField on demand by rafacdb 4 years, 9 months ago
  4. EditingMiddleware (quickly open views and templates in your text editor!) by johnboxall 3 years, 11 months ago
  5. Function to create resized versions of an image from a URL and saving it to a local path by obeattie 6 years, 2 months ago

Comments

(Forgotten your password?)