On Tue, Oct 25, 2011 at 11:10 AM, psbanka <peter.ba...@gmail.com> wrote:
> Am I reading the documentation wrong, or is there a Django error here? > There's a bit of an oddity in Django here, that actually has nothing to do with autoescape. There are three "built-in" tags (block, extends, and include) that are only made available as built-ins as a side-effect of importing the loader module within django.template. So you get the error you noticed if you try to create a Template that uses one of these tags without ever importing django.template.loader. But if you import loader, all works as per the doc you pointed to: Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> ts = """ ... {% autoescape off %} ... <h1>{% block title %}{{ hello }}{% endblock %}</h1> ... {% block content %} ... {% endblock %} ... {% endautoescape %} ... """ >>> from django.template import Template, Context >>> t = Template(ts) Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Users\kmtracey\django\trunk\django\template\base.py", line 124, in __init__ self.nodelist = compile_string(template_string, origin) File "C:\Users\kmtracey\django\trunk\django\template\base.py", line 152, in compile_string return parser.parse() File "C:\Users\kmtracey\django\trunk\django\template\base.py", line 269, in parse compiled_result = compile_func(self, token) File "C:\Users\kmtracey\django\trunk\django\template\defaulttags.py", line 475, in autoescape nodelist = parser.parse(('endautoescape',)) File "C:\Users\kmtracey\django\trunk\django\template\base.py", line 267, in parse self.invalid_block_tag(token, command, parse_until) File "C:\Users\kmtracey\django\trunk\django\template\base.py", line 322, in invalid_block_tag (command, get_text_list(["'%s'" % p for p in parse_until]))) TemplateSyntaxError: Invalid block tag: 'block', expected 'endautoescape' >>> from django.template import loader >>> t = Template(ts) >>> t.render(Context({'hello': 'This & that'})) u'\n\n <h1>This & that</h1>\n \n \n \n' >>> Karen -- http://tracey.org/kmt/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.