Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: any use of blocktrans causes TemplateSyntaxError

Using Django 1.2.1, any use of blocktrans breaks my template. Eg

{%blocktrans%}text{%endblocktrans%}

Results in:

Django Version: 1.2.1 Exception Type: TemplateSyntaxError Invalid block tag: 'blocktrans'

Removing the blacktrans causes the code to work. Django s running on GAE if that's relevant.

like image 937
mikemaccana Avatar asked Feb 07 '11 10:02

mikemaccana


2 Answers

Answering my own question, I'd forgotten:

{% load i18n %}

In the top of the template. This is required to use the blocktrans tag.

Edit: See orokusaki's improved answer below to fix this permanently for all your templates.

like image 160
mikemaccana Avatar answered Oct 25 '22 08:10

mikemaccana


Just add that to your built-in tags like this, instead:

# in urls.py
template.add_to_builtins('django.templatetags.i18n')

Any tag I'm using in multiple templates, I just load into there.

like image 37
orokusaki Avatar answered Oct 25 '22 08:10

orokusaki