django-revcanonical
changeset 2:e4f9a1cebc59 tip
add template tag to return only url
| author | Alexander Solovyov <piranha@piranha.org.ua> |
|---|---|
| date | Mon Apr 13 11:05:19 2009 +0300 |
| parents | 5b5f3eba7efb |
| children | |
| files | README revcanonical/templatetags/revcanontags.py |
| diffstat | 2 files changed, 12 insertions(+), 1 deletions(-) [+] |
line diff
1.1 --- a/README Sun Apr 12 21:41:09 2009 +0300 1.2 +++ b/README Mon Apr 13 11:05:19 2009 +0300 1.3 @@ -39,7 +39,13 @@ 1.4 1.5 Include such code in your template between ``<head>`` and ``</head>`` tags:: 1.6 1.7 - {% load revcanontags %}{% revcanonical object %} 1.8 + {% load revcanontags %} 1.9 + {% revcanonical object %} 1.10 1.11 Of course, you should replace ``object`` with your own object variable. And, 1.12 naturally, it should have ``get_absolute_url()`` method. 1.13 + 1.14 +Additionally you can set your `<a href>` links to short urls:: 1.15 + 1.16 + {% load revcanontags %} 1.17 + <a href="{% shorturl object %}">...</a>
2.1 --- a/revcanonical/templatetags/revcanontags.py Sun Apr 12 21:41:09 2009 +0300 2.2 +++ b/revcanonical/templatetags/revcanontags.py Mon Apr 13 11:05:19 2009 +0300 2.3 @@ -16,3 +16,8 @@ 2.4 if not site: 2.5 site = Site.objects.get_current().domain 2.6 return mark_safe(u'<link rev="canonical" href="http://%s%s">' % (site, url)) 2.7 + 2.8 + 2.9 +@register.simple_tag 2.10 +def shorturl(obj): 2.11 + return reverse('revcanonical', encode(obj))
