• Stars
    star
    405
  • Rank 106,656 (Top 3 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created over 15 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A URL shortening app for Django

django-shorturls

https://travis-ci.org/bfirsh/django-shorturls.svg?branch=master

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

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

Patches welcome: http://github.com/bfirsh/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.

SHORTURLS_DEFAULT_CONVERTER

The converter that is used to translate between short URLs and model IDs. Defaults to the built in base 62 conversion.

Available converters:

  • shorturls.baseconv.base62 Base 62 encoding.
  • shorturls.baseconv.base32 Douglas Crockford's base 32.
  • shorturls.baseconv.hexconv Hex encoding.
  • shorturls.baseconv.bin Binary encoding, because why not.

More Repositories

1

jsnes

A JavaScript NES emulator.
JavaScript
5,921
star
2

jsnes-web

A browser UI for JSNES, a JavaScript NES emulator
JavaScript
586
star
3

serverless-docker

Build serverless apps with Docker
306
star
4

funker

Functions as Docker containers
254
star
5

dynamicaudio.js

An interface for the Web Audio API with a Flash shim for older browsers
JavaScript
168
star
6

loom

Elegant deployment with Fabric and Puppet.
Python
116
star
7

whiskerboard

Stashboard, now with less vendor lock-in.
Python
112
star
8

otter

A server that runs your client-side apps.
CoffeeScript
82
star
9

django-class-based-views

Work on class-based views, now part of Django 1.3. For a backport to Django 1.2, see https://github.com/sorl/django-cbv
Python
79
star
10

serverless-docker-voting-app

A serverless web app built with Docker
HTML
61
star
11

naming-test-suite

How I name products/projects/tools
39
star
12

vNES

A mirror of Jamie Sanders' Java NES emulator, which once lived at virtualnes.com
Java
38
star
13

django-docker-heroku-template

Get a Django app up and running in dev, test, and production with best practices in 10 minutes
Python
36
star
14

python-echoprint

Python library for the Echoprint music identification service
C++
27
star
15

dockerrun

A dead simple Python library for running Docker commands
Python
25
star
16

funker-example-voting-app

An example app using Funker
JavaScript
25
star
17

pspec

Python testing for humans.
Python
21
star
18

syndication-view

Django feeds as class based views, now part of Django 1.2.
Python
21
star
19

pytest_django

A Django plugin for py.test.
Python
19
star
20

django-database-files

A storage system for Django that stores uploaded files in the database.
Python
19
star
21

docker-export-volumes

A Docker image to export volumes from containers
Python
16
star
22

go-dcgi

CGI, but with Docker containers
Go
13
star
23

django-docker-cloud-template

A template for creating Django applications that run on Docker Cloud
Python
12
star
24

funker-go

Funker for Go
Go
12
star
25

heroku-tarsnap-backups

Make offsite backups of Heroku apps on Tarsnap
Shell
11
star
26

docker-redoc

A Docker image which serves ReDoc documentation
HTML
11
star
27

django-mptt

It's MPTT, but with abstract model awesomeness.
Python
11
star
28

funker-python

Python
9
star
29

swarm-viz

HTML
9
star
30

docker-reticulate-splines

Shell
8
star
31

miles

A JavaScript framework for actually getting things done
JavaScript
8
star
32

dotfiles

Vim Script
8
star
33

virtualdocker

Go
8
star
34

rrun

rsync the current directory and run a command over ssh
Shell
7
star
35

herokup

Upload stuff to Heroku that isn't in Git.
Shell
7
star
36

funker-node

JavaScript
7
star
37

jstunes

A JavaScript audio player
JavaScript
7
star
38

docker-sdk-go

WIP: Prototype of a better Go client for Docker
Go
5
star
39

paperpets

Mini origami pets for Little Printer
CSS
5
star
40

fir.sh

SCSS
5
star
41

jsnes-roms

4
star
42

charingcross

Project planning with GitHub issues
Python
4
star
43

docker-api-reference

WIP: Better API reference for Docker, built on Swagger
HTML
3
star
44

vqgan-clip

Python
3
star
45

antsy

Multi-line console animation in Go
Go
2
star
46

cog-segformer

Python
2
star
47

ip

Python
2
star
48

docker-go-client-example

Go
2
star
49

backbone-otter

Tools for writing Otter apps with Backbone
JavaScript
2
star
50

haikuplayer

Python
2
star
51

puppet-cloudkick

A Puppet module for Cloudkick.
Shell
2
star
52

docker-sdk-python

WIP
Python
2
star
53

riffusion-cog

Riffusion as a Cog model
Python
2
star
54

docker-cloud-subdomains

Automatic Heroku-style subdomains for Docker Cloud
Python
2
star
55

internetarchive-pdfjs-isbn-links

JavaScript
2
star
56

hubot-shipping-forecast

CoffeeScript
1
star
57

replicate-screenshots

1
star
58

docker-oauth2_proxy

1
star
59

interlock-haproxy-swarm

Interlock configured to use a Swarm set up by Machine
Shell
1
star
60

python-sdk

Facebook Platform Python SDK
Python
1
star
61

patchwork

JavaScript
1
star
62

compose-mongodb-demo

Python
1
star