Login

Link filter

Author:
sean2000
Posted:
December 14, 2007
Language:
Python
Version:
.96
Tags:
filter links
Score:
2 (after 2 ratings)

Almost too dumb to be worth posting but its saved me a lot of typing.

Instead of:

<div>
    <a href="{{ object.get_absolute_url }} class="object-icon">{{ object }}</a>
</div>

just put:

<div>{{ object|link }}</div>
1
2
3
4
5
6
@register.filter
def link(object):

    return '<a class="%s-icon" href="%s">%s</a>' % (object.__class__.__name__.lower(),
						    object.get_absolute_url(),
						    object)

More like this

  1. really spaceless (trim spaces at line start) by wolfram 7 years, 6 months ago
  2. load m2m fields objects by dirol 5 years, 1 month ago
  3. Filter by first letter inclusion tag by slafs 5 years, 2 months ago
  4. filter for extracting a number of paragraphs from any HTML code by rafadev 4 years, 1 month ago
  5. Page numbers with ... like in Digg by Ciantic 6 years, 3 months ago

Comments

Please login first before commenting.