This post is simply stating the obvious. Sometimes even obvious things, in the wee hours of the morning, aren't so.

When you specify parameters in your URLconf like:

urlpatterns = patterns('',
    url(r'^mark/(?P<id>\d+)/(?P<complete>\d+)/$', views.mark, name='mark'),
)

Keep in mind that each captured argument is a Python string. Even if the regex only captures integers - 'complete' is still passed as a Python string to your 'mark' view.

So if you intended to pass a 0 for false and 1 for true you must make sure to convert to an integer because only a string of length 0 is False. ('0' == True)

def mark(request, id, complete):
    todo = get_object_or_404(pk=id)
    todo.complete = int(complete)
    todo.save()
    return HttpResponse()

Related posts:

  1. Adventures in Django and Python – Part III
  2. Django and Python First Impressions – Part II
  3. Setup Python 2.6.4, mod_wsgi 2.6, and Django 1.1.1 on CentOS 5.3 (cPanel)
  4. Getting Started with Django and Python – First Impressions
  5. Setup Python 2.5, mod_wsgi, and Django 1.0 on CentOS 5 (cPanel)