Blog / Howto

Adding responsive tables (no scrollbars) to your Django app with DataTables

January 13, 2015

It had been over year since I last looked at DataTables, a jQuery table plugin for creating tables with advanced features. I used it for my Django app, GlucoseTracker, and it worked great. But one thing that was bothering me was it wasn't responsive. It was the only element in my app that wasn't responsive and looked horrible when viewing on a phone in portrait mode.

Over the weekend I decided to check …

Adding drag and drop image uploads to your Django site in 5 minutes with DropzoneJS

November 28, 2014

I've been using the Django admin to upload images to my site one-by-one for a few weeks now and I've finally decided I've had enough of it and started looking for a Javascript library that will enable me to do bulk uploads.

I still have around 100 or so albums and at least 1,000 more pictures to upload so you can just imagine how tedious that would be. I found this library called DropzoneJS that …

Ubuntu users: How to upgrade the BIOS of your Dell XPS 13 Ultrabook

November 22, 2014

For a machine being sold with Ubuntu pre-installed, I find it surprising that Dell doesn't have a utility to make BIOS updates easy on Ubuntu.

Dell's BIOS update utility only runs on Windows or DOS.  So for us Ubuntu users, we'll need a way to run DOS on our machines and execute their update utility there.  Luckily, there's FreeDOS.

If you're having stability or performance issues, updating the BIOS is always worth a try. …

How to disable the 'Invalid HTTP_HOST header' emails in Django

November 22, 2014

Ever get these annoying admin emails?

Invalid HTTP_HOST header: '104.131.142.135'. You may need to add u'104.131.142.135' to ALLOWED_HOSTS.

Request repr():
<WSGIRequest
path:/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{},
META:{'HTTP_CONNECTION': 'close',
'HTTP_HOST': '104.131.142.135',
...

The reason you're getting this is because someone's trying to access your site via a host not listed in your ALLOWED_HOSTS setting.  In my case, for this blog, I have just this:

ALLOWED_HOSTS = ['.calazan.com']

So if someone visits my site using a host …

Migrating a Django app from MySQL to PostgreSQL

November 6, 2014

We just finished migrating the database for our Django 1.6 app from MySQL to PostgreSQL. If you have a clean environment this process is as simple as running syncdb and/or migrate to create the tables, truncating the data in those tables, and running the dumpdata and loaddata management commands.

Here are the steps to do this:

Step 1: Create an empty database in your PostgreSQL instance

CREATE DATABASE dbname OWNER rolename;

Step 2: Create a …