Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7419507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:04:58+00:00 2026-05-29T08:04:58+00:00

It maybe a little naive question but I have been trying to understand how

  • 0

It maybe a little naive question but I have been trying to understand how I can use the new Date Based views in django, but without an example, I am at a dead end. What I want to do is to show all my blog entries on a page (with pagination) and in the side navigation I want to show the archiving done according to year and month.

What I want is very basic and can be seen in the picture attached below.

enter image description here

If somebody can provide me an example then it would be really great. I can handle the templates, but just need to know how to use the class based generic views. I haven’t really really used much if generic views.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:04:59+00:00Added an answer on May 29, 2026 at 8:04 am

    The simplest example:

    views.py

    from django.views.generic.dates import MonthArchiveView
    from myapp.models import Article
    
    urlpatterns = patterns('',
        url(r'^articles/monthly/$',MonthArchiveView.as_view(
            model=Article,
            paginate_by=12,
            date_field='publish_date',
            template_name='archive_templates/monthly.html', 
        ),name="monthly"),
    )
    

    You need to call the view with a correct day and month, otherwise you’ll get an exception. Default arguments are year in Y format, and month in b (lowercase short month name).

    Example call articles/monthly/?year=2012&month=feb

    Here is a sample archive_templates/monthly.html you can use.

    I am using css classes from the excellent twitter bootstrap framework. Highly recommended!

    This snippet goes through the available months:

        Archive for {{ month|date:"F" }} {{ month.year }}<br />
        <div class="pagination pull-left">
            <ul>
                {% if previous_month %}
                    <li class="prev">
                        <a href="{% url monthly %}?year={{ previous_month|date:"Y"  }}&month={{ previous_month|date:"b" }}">
                            &larr; {{ previous_month|date:"M Y" }}
                        </a>
                    </li>
                {% endif %}
                {% if next_month %}
                    <li class="next">
                        <a href="{% url monthly %}?year={{ next_month|date:"Y"  }}&month={{ next_month|date:"b" }}">
                            {{ next_month|date:"M Y" }} &rarr;</a>
                    </li>
                {% endif %}
            </ul>
        </div>
    {% endif %}
    

    This snippet does the pagination:

    {% if is_paginated %}
        <div class="pagination pull-right">
            <ul>
                <li class="{% if page_obj.has_previous %}prev {% else %} prev disabled {% endif %}">
                    <a href="{% if page_obj.has_previous %}?page={{ page_obj.previous_page_number }}&year={{ month|date:"Y" }}&month={{ month|date:"b" }}{% else %}#{% endif %}">&larr;</a></li>
                <li class="disabled"><a href="#"><strong>{{ page_obj.number }} of {{ paginator.num_pages }}</strong></a></li>
    
                <li class="{% if page_obj.has_next %}next{% else %} next disabled {% endif %}">
                    <a href="{% if page_obj.has_next %}?page={{ page_obj.next_page_number }}&year={{ month|date:"Y" }}&month={{ month|date:"b" }}{% else %}#{% endif %}">&rarr;</a>
                </li>
    
            </ul>
        </div>
    {% endif %}
    

    The actual list of objects is very simple to iterate over:

    <table class="zebra-striped" width="100%">
        <thead>
        <tr>
            <th>#</th>
            <th>Title</th>
            <th>Author</th>
            <th>Published On</th>
        </tr>
        </thead>
        <tbody>
        {% for obj in object_list %}
            <tr>
                <th>{{ forloop.counter }}</th>
                <td>{{ obj.title }}</td>
                <td>{{ obj.author }}</td>
                <td>{{ obj.publish_date|date:"d/m/Y" }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
    

    From here you should be able to figure out how to develop your archive menu.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe my question it's a little weird, but I'm trying to build a not-so-simple
Maybe dumb question: I'm trying to realize a little server in Java with com.sun.net.httpserver
Maybe this is a little unconventional question but I'd like to hear an answer
The question maybe a little confusing, but it's hard to make clear this question
Maybe a little tricky, but I wonder why. In System.Linq.Enumerable.cs of System.Core.dll we have:
I have maybe a little bit strange task, but I belive there is no
OK, that question sounds maybe a little confusing so I'll try to explain it
Maybe the title is a little missleading but I'd like to ask you for
Maybe this sounds a little bit crazy, but I need to come up with
I find this question a little tricky. Maybe someone knows an approach to answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.