Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install django-shorturls

How to install django-shorturls

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install django-shorturls
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0.1 Available View build log
Windows (64-bit)
1.0.1 Available View build log
Mac OS X (10.5+)
1.0.1 Available View build log
Linux (32-bit)
1.0.1 Available View build log
Linux (64-bit)
1.0.1 Available View build log
 
License
BSD
Dependencies
Lastest release
version 1.0.1 on Jan 5th, 2011

django-shorturls

A custom URL shortening app for Django, including easy rev=cannonical support.

Most code was originally by Simon Willison; see http://simonwillison.net/2009/Apr/11/revcanonical/ for details. Improved slightly and packaged by Jacob Kaplan-Moss.

Patches welcome: http://github.com/jacobian/django-shorturls

Usage

So, you want to host your own short URLs on your Django site:

  1. In your settings, define a set of prefixes for short URLs:

    System Message: WARNING/2 (<string>, line 20)

    Literal block expected; none found.

SHORTEN_MODELS = { 'A': 'myapp.animal', 'V': 'myapp.vegetable', 'M': 'myapp.mineral' }

The keys are string prefixes; they can be any string, actually, but since we're going for short a single character is probably good.

Values are the (hopefully-familiar) "<app-name>.<model-class>" used by Django to identify a model. Remember: app-name is the (case-sensitive) last bit of your app's name in INSTALLED_APPS, and <model-class> is your model class's name, lowercased.

Make sure your models have a get_absolute_url() method defined.

  1. Wire up the redirect view by adding to your URLconf:

    System Message: WARNING/2 (<string>, line 38)

    Literal block expected; none found.

('^short/', include('shorturls.urls'))

3. If you'd like to quickly link to shortened URLs in your templates, stick "shorturls" in INSTALLED_APPS, and then in your templates do:

{% load shorturls %}

System Message: ERROR/3 (<string>, line 44)

Inconsistent literal block quoting.

<a href="{% shorturl object %}">...</a>

(where object is a model instance).

Alternatively:

{% load shorturls %}
{% recanonical object %}

This generates the whole <link rev="canonical" href="..."> tag for you.

That's it.

If you'd like more control, keep reading.

Settings

Available settings are:

SHORTEN_MODELS You've seen this one.

SHORT_BASE_URL If defined, the shorturl and revcanonical template tags will prefix generated URLs with this value. Use this if you've got a shorter domain name you'd like to use for small URLs.

For example, given SHORT_BASE_URL = 'http://exm.pl/', {% shorturl obj %} would return something like http://exm.pl/AbCd.

SHORTEN_FULL_BASE_URL The domain to redirect to when redirecting away from the small URL. Again, you'll use this if your short URL base and your "real" site differ.

If not defined, the redirect view will try to guess the proper domain by consulting the django.contrib.sites framework, if installed, or the requested domain, if not.

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:2

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.