开发者

django:error with the custom inclusiong_tag, error info:Invalid block tag

开发者 https://www.devze.com 2022-12-15 04:03 出处:网络
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 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 impo开发者_如何学JAVArt 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 %}


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 %}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消