在 Django 利用 tags 生成 calender

Hoho

calender.html 模版:

{% for dayname in daynames %}{% endfor %}
{% for week in weeks %}

        {% for day in week %}

        {% endfor %}

{% endfor %}

{{ month }} {{ year }}  
---

{{ dayname }}  
{{ day }}

calender include_tags

def calendar_table():
    import calendar
    import datetime
    date = datetime.date.today()
    month = calendar.monthcalendar(date.year, date.month)
    weeks = [[day or '' for day in week] for week in month]
    return {
        'month': calendar.month_name[date.month],
        'year': date.year,
        'weeks': weeks,
        'daynames': calendar.day_abbr,
    }
register.inclusion_tag('qin/calender.html')(calendar_table)

具体怎么应用 tags 这里就不说了. 哈哈哈