Skip to content

Instantly share code, notes, and snippets.

View longlho's full-sized avatar

Long Ho longlho

View GitHub Profile
@trey
trey / redirects_in_django.md
Created May 23, 2012 12:26
Smart URL Redirects in Django

Smart URL Redirects in Django

While building [ComicBinder][cb]'s URLs, I wanted a way to differentiate a volume of a title other than one, and a printing of an issue other than one. So, for example, a URL to the second printing of the second volume of Amazing Spider-Man #1 would look like:

/marvel/amazing-spider-man_2/1_2/

That's easy enough with some URLconf wrangling. What I'm talking about today is automatically redirecting a request for _1 in any of those places to the same URL without the _1. While technically correct, I want the lack of underscore + number to mean one, and for there to be only one URL for a resource (someone send me a link to a clever article that talks about this).

django.views.generic.simple.redirect_to to the rescue. Try something like this:

@bhang
bhang / install_graphite_statsd_ubuntu_precise.sh
Created May 15, 2012 17:41
Install Graphite and statsd on Ubuntu 12.04 LTS (Precise Pangolin)
#!/bin/bash
# node.js using PPA (for statsd)
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
# Install git to get statsd
sudo apt-get install git