Ian Lewis Ian Lewis is a web developer living in Tokyo Japan. His current interests are in Go, Python, alternative databases and rapid web application development.
About Me...

Testing Django Views Without Using the Test Client

The normal way to test Django views is via the test client. The test client fakes being a wsgi server and actually makes an HTTP request through all of Django’s request routing machinery. There are a number of reasons why this isn’t an ideal approach. ## Tests are Slow When you use the Django test server, you are making an HTTP request from the WSGI server level on up. This invokes logic fo[...]

Administer WordPress using Django's Admin

I recently came across one feature of Django that seemed pretty useful for one off projects and customizations and was startled because it's one of Django's least mentioned features.

Django's contrib.auth and django-newauth

Recently there have been a lot of conversations on the Django mailing list about fixing the auth module. Here are some of the recent mailing list threads: 1. authentication by email 2. auth.User refactor: reboot 3. auth.User: The abstract base class idea Originally the topic came up because of the fact that you can't really authenticate effectively using the email address as a usernam[...]

bpssl - The Django SSL Support Application

The other day I released bpssl which is a Django application that helps you support HTTPS on your website. The main functionality is performing redirection for HTTPS only URLs and views. For instance, if a request for your login view '/login' is recieved over HTTP, the provided middleware can redirect the user to the equivalent HTTPS page. Specifying views and urls as secure is supported as [...]

'self' ForeignKeys always result in a JOIN

I came across a little annoyance in Django today. I found that ForeignKeys that reference 'self', i.e. they point to the same table, always result in a join in a filter. Take this normal foreign key reference. class Customer(models.Models): user = models.ForeignKey(User) >>> Customer.objects.filter(user__isnull)._as_sql() ('SELECT U0."id" FROM "acco[...]

Django template2pdf

This is cool Django application from Yasushi Masuda which allows you to render data to a pdf using trml2pdf. template2pdf provides a generic view called direct_to_pdf which will render a rml template directly to pdf. # coding: utf-8 from django.http import HttpResponse from django_trml2pdf import direct_to_pdf from django.shortcuts import render_to_response [...]

Running django with daemontools

Running django fastcgi with daemontools is rather easy but getting it to run in the foreground with the proper user takes a bit of knowledge about how bash works and the tools in daemontools. In order to run the fastcgi daemon in the foreground you need to specify the daemonize=false option to the fastcgi command. Next the daemon will be started as the root user unless the daemon has an opt[...]

Testing HTTPS with Django's Development Server

Django's development server doesn't normally support HTTPS so it's hard to test applications with HTTPS without deploying the application to a real web server that supports HTTPS. The secret is to use two development server instances, one for http and one for https, and to use a tool called stunnel to can create an ssl tunnel to the development server to support HTTPS. First we need to set u[...]

Minimum cost for warming-up various frameworks(and more)

My good friend Takashi Matsuo wrote an interesting blog about start up times of various frameworks on appengine. Because appengine kills your server process it often needs to load your application into memory from scratch. This can take a lot of time if a lot of modules are loaded. http://takashi-matsuo.blogspot.com/2009/10/minimum-cost-of-various-frameworks- cold.html

Testing using a mocked HTTP server

Recently I got some tests working for my django-lifestream project. The lifestream imports data from RSS/Atom feeds so there isn't a good way to run tests without creating a test HTTP server to serve up your RSS/Atom. The tests start up an http server in a separate thread which serves rss/atom/xml files from a set test directory. I copied the test http server which was used for feedparser's [...]