Technical Article | Feb 19, 2014

Django Debugging Bookmarklet Trick

by Frank Wiles

So this is one of those little things where you think, why the hell didn't I think of this years ago?

I'm sure many Django developers end up doing this on a fairly regular basis. You're working on a site, go to the production/staging version, navigate around and then want to view the same URL path but on your local development server.

If you're like me you cut-n-paste the current URL into a new tab and manually remove the host and replace it with http://localhost:8000. That way you have a browser tab of the real site and a tab with the local version for comparision. I've done this at least a billion times. It's a silly little annoyance because it's easy to mess up the URL leaving off the slash after 8000 for example.

This morning while working on a site I realized, WTF I can do this with a bookmarklet! They're super easy as it turns out.

Version that replaces the current tab:

javascript:(function() { window.location.replace("http://localhost:8000" + window.location.pathname); }())

Version that creates a new tab:

javascript:(function() {  window.open("http://localhost:8000" + window.location.pathname, '_blank'); }())

I still can't quite believe I didn't think to do this long ago! I wonder how many hours of time I would have saved over the years? I've included two links below that you can create your own bookmarks from, you'll obviously need to edit them if you don't use the Django defaults of localhost:8000.

Simply drag which ever version you prefer into your bookmarks and you're ready to go.

Make localhost:8000

Make localhost:8000 tab

You could easily modify these to create bookmarklets that take you to your staging or QA system and even when working with development frameworks other than Django.

Hope this saves you as much time as it is going to save me!

UPDATE: Jacob sent me a great additional add-on tip to this. Michael Mahemoff has a good tip on how to change the Favicon in your browser between different environments like staging and production. So you can combine these two techniques for maximal win!

Recent Posts

Technical | Frank Wiles

Improved Django Tests

You write tests. Or at least you should be writing tests! As Jacob always says, "Code without tests is broken as designed."

Unfortunately you have to write a ton of boilerplate code to test even the simplest of things. This ...

Technical | Frank Wiles

Django Performance: 4 Simple Things

Optimizing for performance often comes with a bunch of headaches and hard problems, but it doesn’t always have to be that way.

Below are four simple things you can do to quickly and easily improve the performance of your ...

Technical | Frank Wiles

Wagtail 1.0 (beta) best Django CMS?

Now that the Wagtail CMS is gearing up for its 1.0 release, I wanted to take some time to introduce you to the all around best and most flexible Django CMS currently available. Wagtail has been around for a ...

All Posts

We are perfor­mance tuners, Django and PostgreSQL experts, infrastructure and scaling architects.

Learn More

A little bookmarklet that redirects you from the current page to the same path on http://localhost:8000/. Helpful when debugging Django.

2014-02-19T08:28:41 2015-05-29T05:29:45.415126 2014 django, debugging, bookmarklet, localhost