Skip to content


Published on: February 10, 2008    Categories: Django, Meta

Between normal work, working on the book, working on my upcoming PyCon talk and working on a couple little things on the side, I haven’t had much time for blogging lately, especially about Django. But I’ve built up a collection of little things that need to get posted, so I’m just going to start dumping them out here and then get back to not having any free time :)

A django-registration update

I’ve bumped django-registration up to version 0.4p2; the new package doesn’t add any new features, but it does have a few documentation fixes and three new translations: Brazilian Portuguese, Japanese and Hebrew. As always, bug reports are appreciated; I’m closing in on a point where I think I’ll be ready to call it “1.0”, and I’d like to get it as robust as possible before I do that.

Ideally I’d like to push it to 1.0 right around the time Django goes to 1.0, but I don’t know if that’ll happen.

A quick template trick

While working on a write-up of the Django template system for the book, I noticed an interesting feature of the “regroup” tag I’d never noticed before: the documentation mentions that you can use a filter on the data structure to be regrouped, but leaves out the fact that you can also use a filter on the attribute to regroup by.

To see why this is incredibly cool, consider the output of the archive_year generic view when you pass make_object_list=True; you get back a list of all the objects in the given year. Now, in a lot of cases it’s nice to show them broken up into groups according to month; for example, an archive of blog entries or news stories would want to do this. In the past I’d always used something like the following (taken from the template for the yearly archive of entries on this blog):

<h2>Entries in {{ year }}</h2>
{% for entry in object_list %}
{% ifchanged %}</ul>
  <h3>{{ entry.pub_date|date:"F" }}</h3>
{% endifchanged %}
  <li><a rel="bookmark" href="{{ entry.get_absolute_url }}">{{ entry.title }}</a></li>
{% endfor %}

This uses the “ifchanged” tag to figure out when it’s moved into a new month, but is pretty complex and results in an extra “empty” ul element. The same thing can be accomplished, much more cleanly and without that extra ul, by using regroup:

<h2>Entries in {{ year }}</h2>

{% regroup object_list by pub_date|date:"F" as month_list %}

{% for month in month_list %}

<h3>{{ month.grouper }}</h2>
  {% for entry in month.list %}
  <li><a rel="bookmark" href="{{ entry.get_absolute_url }}">{{ entry.title }}</a></li>
  {% endfor %}
{% endfor %}

Note that the “attribute” to regroup by includes a filter: date:”F”, which will format the pub_date of the entry into the full name of the month (e.g., “February”); so this not only organizes the entries by month, it also splits them up into groups headed by the full name of the month.

Nathan tells me he uses regroup like this all the time; I must be slow, because I never knew it could do that.

Another media trick

I’ve seen a couple people on django-users today complain that they’re having trouble serving their site’s media files under the development server (using the django.views.static.serve view as mentioned in the static files documentation). This can be a tricky thing to set up, especially if you’re a newcomer to Django and don’t yet fully grok the regular-expression syntax for URL configuration.

I personally don’t use that when I’m doing things locally under the development server; instead, I rely on the fact that OS X comes with Apache already installed and configured, and makes it really easy to use for situations like this. Here’s what to do:

  1. In OS X’s System Preferences dialog, go to the “Sharing” pane; there’s a section titled “Web Sharing”. Turn it on, and Apache will start up; it’ll show you your computer’s URL (based on its current IP address, so it’ll be something like and also the URL you can use to access any of your own files that you’ve set up for serving (based on a username prefix, so something like
  2. In your home directory is a folder called “Sites”. Anything you put in there will automatically be served by the now-running Apache, at the URL for your “personal” files.

I tend to take advantage of the fact that OS X will also let you access your own computer by name, in the special domain “.local”; I’ve named my laptop “marengo” and my username is “jbennett”, so I can access its preinstalled Apache at http://marengo.local/~jbennett/. In my “Sites” folder I’ve got various folders holding media files for things I’m developing, and then I just fill in MEDIA_URL in Django to be http://marengo.local/~jbennett/some-site-name/ accordingly.

Come work for us!

As Matt pointed out the other day, we’re hiring for several positions. Like any software company, we’ve got our share of boring and mundane tasks — installing and configuring things, supporting all of our existing deployments, etc. — but unlike pretty much any other company, we’ve got a staff of some of the smartest and most creative people on the Web combined with the freedom to do new and interesting things with the news (when was the last time your local paper posted real-time election results to Twitter?), and we’re changing our industry, one Django install at a time.

And that’s without mentioning what a cool and eclectic little town Lawrence is. I think Jacob’s description from a hiring period a couple years ago is probably the best; it won me over, I applied a couple days later and the rest is history. With two years’ experience of living here under my belt, I can attest to the fact that he’s right:

Lawrence could be one of the coolest towns in America. If you take every negative stereotype of Kansas and turn them on their heads, you’d get Lawrence. We have an amazing local music scene (which exhaustively covers) and a downtown so vibrant it put a mall out of business. Lawrence’s reputation as a “music town” reaches far and wide, and so we get great national acts that bypass most towns ten times Lawrence’s size.

If you’re used to the insane cost of living in most big cities, Lawrence will blow your mind. You’ll easily be able to afford a brand new apartment, or one within walking distance of downtown, or a turn-of-the-century house. Food’s incredibly cheap, too; the best barbecue dinner of your life is less than ten bucks.

Plus, we’re the one and only home of Django, and we use it exclusively. You just can’t beat that.

We’re looking for both senior and junior developers, so anybody who likes and wants to work with Django should consider getting in touch.