github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jacobian / django-shorturls

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 127
    • 7
  • Source
  • Commits
  • Network (7)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

A URL shortening app for Django. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Fixed a typo in the readme 
d0ugal (author)
Mon Dec 14 15:25:21 -0800 2009
jacobian (committer)
Tue Dec 15 09:17:42 -0800 2009
commit  1012b4afe8cb8a2952b4cbfc3d29d57de4ba53e4
tree    5568ee4dddcc26033251feb23b2460eadfeeef44
parent  3a16e5d48ce6125fd9e5fc6573ffb80bd540c697
django-shorturls /
name age
history
message
file .gitignore Sun Apr 12 17:52:06 -0700 2009 Fixed a Python 2.5ism. [jacobian]
file LICENSE Sun Apr 12 13:02:44 -0700 2009 Buildout bootstrap setup. [jacobian]
file README Tue Dec 15 09:17:42 -0800 2009 Fixed a typo in the readme [d0ugal]
file bootstrap.py Sun Apr 12 13:02:44 -0700 2009 Buildout bootstrap setup. [jacobian]
file buildout.cfg Mon Apr 20 08:29:51 -0700 2009 Added an interpreter, and also added a way to t... [jacobian]
file setup.py Sun Apr 12 20:22:02 -0700 2009 Updated classifiers a bit. [jacobian]
directory src/ Wed Apr 29 11:25:09 -0700 2009 Moved the baseconv tests into the test suite so... [jacobian]
README
django-shorturls
================

A custom URL shortening app for Django, including easy ``rev=canonical``
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::

        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.
    
2. Wire up the redirect view by adding to your URLconf::

        ('^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 shorturl %}
        <a href="{% shorturl object %}">...</a>
        
   (where ``object`` is a model instance).
  
   Alternatively::
  
        {% load shorturl %}
        {% revcanonical 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.
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server