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. Simple "html email with images" sender by andres_torres_marroquin 3 years, 1 month ago
  2. iPernity thumbnail helper by sedden 5 years, 5 months ago
  3. Auto Generate/Save Thumbnails using Template Filter (scale max_x, max_y, or both) by ThisbeTom 5 years, 4 months ago
  4. Dom ID by bmihelac 4 years, 5 months ago
  5. Sending html emails with images using Django templates by sleytr 6 years, 10 months ago

Comments

(Forgotten your password?)