home.html

{% extends "layout/base2.html" %}
{% load generic_content %}
{% load blog_extras %}




{% block cont_actu %}
{% get_latest_objects blog.entry 5 as latest_entry %}
{% display_last_entry %}



{% endblock cont_actu %}

blog_extras.py

﻿# -*- coding: utf-8 -*-
from django import template
from django.template import Library, Node, TemplateSyntaxError
from django.conf import settings
from monsite.blog.models import Tag,Entry




register = template.Library()


@register.inclusion_tag('blog/tag_list.html')
def show_alltags():
	allmytags = Tag.objects.order_by('name')
	return {'alltags': allmytags}

@register.inclusion_tag('blog/archive_by_year.html')
def archive_by_year():
	year_list = Entry.objects.dates('pub_date','year', order='ASC')
	return {'year_list': year_list}

@register.inclusion_tag('blog/archive_by_month.html')
def archive_by_month():
	month_list = Entry.objects.dates('pub_date','month', order='ASC')
	return {'month_list': month_list}


def display_last_entry(context):
    """
    Display latest posts, ``latest_posts`` var should be in the context.

    Usage::

        {% get_latest_objects journal.Post 5 as latest_posts %}
        {% display_footer_posts %}

    This will use ``display_footer_posts.html`` template.
    """
    return { 'latest_entry': context['latest_entry'] }



register.inclusion_tag('blog/display_last_entry.html', takes_context=True)(display_last_entry)

display_last_entry.html

<h3>Derniers billets publiés</h3>
<ul>
{% for entry in latest_posts %}
    <li><a href="{{ entry.get_absolute_url }}" title="Lire le billet intitulé {{ entry.title }}">{{ entry|safe }}</a></li>
{% endfor %}
</ul>