Template tags in Django

Posted on 2008-06-15 22:36:06

I was messing around today with django-gencal but the lack of an easy to follow documentation was a bit of a problem. I got some help from the official Django docs but most especially from this excelent post/howto from James Bennett.

PS: Just needed to reference this for future use. My delicious account has way too much stuff.

Tags: django, template tags


Comments


  • Justin Lilly

    Hey Marco,
    Glad you got it working. I'm actually improving gencal's documentation this week as it /is/ a bit hard to follow. Hopefully it all worked itself out. Thanks so much for trying it out!

  • J-Chris

    Hi Marco,

    Could you provide me a snippet code showing how you are using the gencal module. It would save me some times :)
    Thks

  • Marco

    Hi J-Chris,

    The current version of gencal is probably a bit different than the one I tested, but anyway..

    View:

    from django.shortcuts import render_to_response, get_object_or_404
    import datetime

    def index(request,year,month):

    cal_items = [{ 'day':datetime.datetime(2008,6,30), 'title':"Concert at Huckelberries", 'class':"concert", 'url':'/foo/2' },
    { 'day':datetime.datetime(2008,6,4), 'title':"BBQ at Mom\'s house", 'class':"restaurant", 'url':'/restaurants/9' }]

    return render_to_response('project/index.html', { 'month': month,
    'year': year,
    'cal_items' : cal_items })

    In the template all you need is this:

    {% load gencal %}
    {% gencal cal_items %}

Leave a reply