tags:

views:

41

answers:

2

I'm trying to write a custom inclusion_tag in django.

Following the example on http://docs.djangoproject.com/en/dev/howto/custom-template-tags/

I'm just writing

from django import template
from libmas import models

register = template.Library()

@register.inclusion_tag('records.html')
def display_records(book_id):

    book = models.book.objects.get(id__exact=book_id)
    records = models.objects.filter(books=book)[0:10]

    return {'records':records}

But I'm getting a

Invalid block tag: 'libmas_tags' 

error in ie .

'records.html' file:

{% for record in records %}
<blockquote>{{record.id}}</blockquote>
{% endfor %}

my other html file is :

{% extends "admin/change_form.html" %}

{% libmas_tags %}

{% block after_field_sets %}

{% if object_id %}
{% display_records object_id %}
{% endif %}

{% endlock %}
A: 

The problem lies in your template. Its calling {% libmas_tags %}. Have you created template tags called libmas_tags? If so you might need to change it to

{% load libmas_tags %}
czarchaic
A: 

What is libmas_tags? The tag you have defined is called display_records, and that's what you should be calling in your template. If the tags file is called libmas_tags, you'll need to load that first as czarchaic points out.

Daniel Roseman
libmas_tags is a file named libmas_tag.py. Now i modified:load libmas_tag as crarchaic.but i also get a new error:'libmas_tags' is not a valid tag library: Could not load template library from django.templatetags.libmas_tags, cannot import name models
wangshiyun
That means there is an error in the libmas_tags file
czarchaic