About     Search     Feed

Nilesh D Kapadia


Music     Twitter     Github

URL Shortener Web Application Using Django

I created a URL shortener web application using Django (a Python web framework). I have made the source code available on GitHub and it is under an open source license (MIT license).

The shortened URLs use the base 62 value of ids of the model they are stored in, using the code from here (it uses A-Z, a-z, and 0-9), which should be fairly compact for a long time. A count of how many times the URLs are used is kept. The main page shows the 10 most recent and 10 most popular URLs.

You can see a running instance at n1l.us (which I am using to link to this blog and other links to my own content) and uu4.us (which I am using for all other URLs). I currently don't allow public submissions of URLs on either of those sites, but I will be opening it up for uu4.us at some point (perhaps once I add some defenses against spammers). The application itself has a configuration option to be able to require or not require login to be able to submit URLs (the REQUIRE_LOGIN setting in settings.py). Note that if you require logins, you have to use the admin app (at /admin/) as I have not created a separate login page.

I've so far done the bare minimum as far as HTML/JavaScript is concerned (and there is no CSS to speak of yet). Just enough to get things working. So don't expect a good looking site with this yet. It does produce a functional bookmarklet, assuming that you set SITE_NAME correctly for your site. Though I should probably make the bookmarklet check for rev=canonical to be a good web citizen.

This was developed using the current Django from SVN. I don't believe I used any features specific to 1.1, so it may work with 1.0.x, but I'm not absolutely sure.

Note that django-shorturls solves a different problem and is not a general URL shortener. It is to be used in an existing Django application to automatically map short urls to specific model instances and to produce the containing the short url in the templates.

© 2017 Nilesh D Kapadia