Template Tags and TemplateSyntaxError: - expected 'endblock' or 'endblock content'

1,219 views
Skip to first unread message

Mazery Smith

unread,
Mar 18, 2011, 10:48:31 AM3/18/11
to Django users
newbie here,
I'm running into a template syntax error where (as far as I can tell)
there shouldn't be one (yes, I've loaded my tags file before I tried
invoking my tag). I'm looking for help on how to debug it. I'm running
Django trunk.

I'm using template inheritance with a custom tag for pagination help.
I currently have "introContent.html" extending a "base.html" file. I
want to use a "pagination_links" tag from my "page_tags.py" tag file
(this example is from the Django e-commerce book)

---------------------------------------------
# In introContent.html

{% extends base.html %}

{% block content %}

{% load page_tags %}

{% pagination_links request paginator %}

{% endblock %}
---------------------------------------------

When I run this i get the error "expected 'endblock' or 'endblock
content".

I'm sure this error can mean multiple things.

Is there anyway this error could be thrown by invalid syntax within
the pagination_links.html that the pagination_links tag registers?

I think the most useful help could possibly talk about debugging
methods they use (i'm working remotely) as well as areas where this
Template Syntax Error is known to be thrown

Shawn Milochik

unread,
Mar 18, 2011, 11:17:14 AM3/18/11
to django...@googlegroups.com
Are you certain that your base template is structured properly? Check
for missing closing tags.
It may be that your template is correct but just inheriting a syntax problem.

Shawn

Mazery Smith

unread,
Mar 18, 2011, 11:32:41 AM3/18/11
to Django users
Thanks Shawn,
That's a good tip. I'll check when I get back home and give an update

Daniel Roseman

unread,
Mar 18, 2011, 11:36:52 AM3/18/11
to django...@googlegroups.com
On Friday, March 18, 2011 2:48:31 PM UTC, Mazery Smith wrote:
newbie here,
I'm running into a template syntax error where (as far as I can tell)
there shouldn't be one (yes, I've loaded my tags file before I tried
invoking my tag). I'm looking for help on how to debug it. I'm running
Django trunk.

I'm using template inheritance with a custom tag for pagination help.
I currently have "introContent.html" extending a "base.html" file. I
want to use a "pagination_links" tag from my "page_tags.py" tag file
(this example is from the Django e-commerce book)

---------------------------------------------
# In introContent.html

{% extends base.html %}

{% block content %}

     {% load page_tags %}

     {% pagination_links request paginator %}

{% endblock %}
---------------------------------------------

When I run this i get the error  "expected 'endblock' or 'endblock
content".


If that is the entire template, then you definitely do have an error - you haven't loaded the templatetag library that defines pagination_links. You need to load libraries in *every* template that uses them, even if it extends another one.
--
DR.

Mazery Smith

unread,
Mar 18, 2011, 12:35:12 PM3/18/11
to Django users
Thanks for the response DR.

Isn't the "template tag library" already loaded in my example with
this line:

{% load page_tags %}

My pagination_links tag is in the page_tags.py file. So that should
work. Unless you are saying that the parent template (base.html that
introContent.html extends) needs to have a load statement in it too.
Is that what you are saying?

Just wondering b/c I don't really extract that meaning from the Djano
docs here:
http://docs.djangoproject.com/en/dev/topics/templates/#custom-libraries-and-template-inheritance
""""
When you load a custom tag or filter library, the tags/filters are
only made available to the current template -- not any parent or child
templates along the template-inheritance path.

Daniel Roseman

unread,
Mar 18, 2011, 12:50:04 PM3/18/11
to django...@googlegroups.com
On Friday, March 18, 2011 4:35:12 PM UTC, Mazery Smith wrote:
Thanks for the response DR.

Isn't the "template tag library" already loaded in my example with
this line:

{% load page_tags %}

My pagination_links tag is in the page_tags.py file. So that should
work. Unless you are saying that the parent template (base.html that
introContent.html extends) needs to have a load statement in it too.
Is that what you are saying?

Just wondering b/c I don't really extract that meaning from the Djano
docs here:
http://docs.djangoproject.com/en/dev/topics/templates/#custom-libraries-and-template-inheritance
""""
When you load a custom tag or filter library, the tags/filters are
only made available to the current template -- not any parent or child
templates along the template-inheritance path.
"""

Sorry, my mistake: I didn't see the load tag (I always put them at the top of the file after extends, so wasn't looking in the right place). Apologies, you are right.

My only suggestions are: are you sure page_tags actually does define the "pagination_links" tag? Could there possibly be two page_tags templatetag libraries? As a last resort, have you tried deleting the .pyc files in your project (or just in your templatetags directory)?
--
DR.

Mazery Smith

unread,
Mar 18, 2011, 12:55:15 PM3/18/11
to Django users
Those all are good ideas DR (especially the last resort pyc b/c I
heard that screws things up once in awhile) and I will try them when I
get home and update.

Really, any ideas helps. Thanks a ton!

On Mar 18, 9:50 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Friday, March 18, 2011 4:35:12 PM UTC, Mazery Smith wrote:
>
> > Thanks for the response DR.
>
> > Isn't the "template tag library" already loaded in my example with
> > this line:
>
> > {% load page_tags %}
>
> > My pagination_links tag is in the page_tags.py file. So that should
> > work. Unless you are saying that the parent template (base.html that
> > introContent.html extends) needs to have a load statement in it too.
> > Is that what you are saying?
>
> > Just wondering b/c I don't really extract that meaning from the Djano
> > docs here:
>
> >http://docs.djangoproject.com/en/dev/topics/templates/#custom-librari...

Mazery Smith

unread,
Mar 19, 2011, 8:20:34 AM3/19/11
to Django users
So i figured out the with my inclusion tags pretty quick...the syntax
error was generated within the page_tags.py b/c I had my registration
"@register.inclusion_tag("pagination_links.html")" statement without
the "@" decorater symbol

Now my only question how this mistake bubbled up into a
TemplateSyntaxError related to endblocks?

Any ideas?
Reply all
Reply to author
Forward
0 new messages