I am working with Django’s generic views, specifically django.views.generic.date_based.archive_month.
This views sets the template context to include date_list which contains a list of the relevant python datetime.datetime objects. (See https://docs.djangoproject.com/en/1.4/ref/generic-views/#django-views-generic-date-based-archive-month)
This my simple template to use this view:
<html>
<head>
<title>Entries index</title>
</head>
<body>
<h1>Entries index by month: {{ month|date:"F" }}</h1>
<h2>Day:</h2>
{% for datetime_object in date_list %}
<ul><a href="/weblog/{{ year }}/{{ month.month }}/{{ datetime_object.day }}/">{{ datetime_object.day }}</a></ul>
{% endfor %}
</body>
</html>
My problem is that although I can get the numerical month, say 3 for march, my urls are set up to use the three letter representation, i.e. mar for march, so that <a href= block isn’t pointing to the right url.
How can I set up a mapping to map each of the month’s numerical value to their three letter representation?
You can use the built-in
datetemplate tag with thebformat character.Applied example below: