1. Overview
2. Download
3. Install
4. Check it Out


1. Overview

Name     : django-url-reduce
Author   : Kieran Lynn <kieran@octothorpstudio.com>
Date     : December16, 2010

NOTE: This package is still under active developmend and is subject to change.

URLreduce (django-url-reduce) is a Django pluggable app that provides a URL
shortening service globally to any URL in your site (automatially) or any external
URL you wish to add.

The goal of URLreduce is to not only make it easy to provide shortened URL's, but
to also provide compliance with the rel-shortlink specification as defined by
microformats.org (http://microformats.org/wiki/rel-shortlink).

By installing the URLreduce middleware, you are enabling URLreduce to check any
incoming request to see if it has a shortened URL in the database, if it does not
one is created. Your output response is then modified to include the Link attribute
(Link: <http://flic.kr/p/6XuLyD>; rel="shortlink") and the meta element is injected
into the head of your docuement:

<link rel="shortlink" type="text/html" href="http://flic.kr/p/6XuLyD">


2. Download

Project Home:
https://github.com/octothorp/django-url-reduce

Downloads are available via GitHub:
git clone git@github.com:octothorp/django-url-reduce.git

or

The Python Package Index
http://pypi.python.org/pypi/django-url-reduce/


3. Install

First add urlreduce to your INSTALLED_APPS in settings:

INSTALLED_APPS = (
    ...
    'urlreduce',
    ...
)

Next add the urlreduce middleware to settings:

MIDDLEWARE_CLASSES = (
    ...
    'urlreduce.middleware.UrlShortnerMiddleware'
    ...
)

In your main url.py, add the url configuration for the url forwarder. The prefix,
in this case x, can be any string. It is best to keep it short.

urlpatterns = patterns(
    '',
    ( r'^x/', include( 'urlreduce.urls' ) ),
    ...
)

If you would like to use the SHORTLINK template tag to get the shorlink URL, add
the context processors in settings.py:

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.request',
    ...
    'urlreduce.context_processors.shortlink',
)

Now you are configured and ready to go. Just run sync db to create the links table:

> python manage.py syncdb


4. Check it Out

Now when ever you nload you site pages, you can view source and just above the
head tag you should see a meta tag with the short link for you page:

<link rel="shortlink" href="http://127.0.0.1:8000/x/d34" />

Notice that all urls have the x prefix for the urls.

If you have a tool like Firebug, you can also look at the Response Headers and find
the Link header:
Link: <http://127.0.0.1:8000/x/d34>; rel="shortlink"