ntoll.org

(Everything I say is false...)
home | about | articles | presentations | cv | contact

Django Microformats

Sunday 19 April 2009 (03:11PM)

I've just created a new Django application that makes it easier to integrate and use Microformats in your web-application. I'm hosting it on GitHub:

http://github.com/ntoll/microformats/tree/master

All you need to do is run the following command from within your own Django project:




git clone git://github.com/ntoll/microformats.git



... and remember to add it to the INSTALLED_APPS section of your settings.py file.

Microformats are a means of adding semantic information that is both human and machine readable to a web-site. In order to work with Microformats you need to use a toolkit such as Oomph or the Operator Add-on for Firefox (that supports more types of microformat).

The following YouTube video from the Oomph team pretty much explains the basics:

By using the Django microformats application you get the following:

To use the template filters you need to register the application and add:

{% load microformat_extras %}

to the top of the template you're using.

For an example of this in use check out the end of the following test file:

microformats/unit_tests/test_templatetags.py

Running the unit tests (./manage.py test microformats) will result in an example file demonstrating the HTML markup produced by the template filters:

microformats/unit_tests/html_test/microformat_test.html

I've included the Oomph javascript library so you can play with the microformats if you open the file in your browser. If you're using Firefox try it with the Operator add-on. IE8 supports Microformats natively.

This is a first shot at integrating Microformats into Django. There are missing microformats and I'm pretty sure some of the models could be improved as could the template filters. Inevitably the code needs to be cleaned up too. I'll be using this library in a new web-application so expect this code to change as I find flaws and gremlins through using it "in anger".

Feedback would be most welcome.