Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#24451 closed Bug (fixed)

TemplateSyntaxError with {% cycle "Hello, how are you?" "Fine!" %}

Reported by: Carsten Fuchs Owned by: Tim Graham
Component: Template system Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Originating thread at django-users: https://groups.google.com/forum/#!topic/django-users/hSqSVpWMDqs

Using Django 1.7.5, there is a problem with commas in string literals in the cycle tag, e.g. with

    {% cycle "Hello, how are you?" "Fine!" %}

Please consider this example in the management shell (newlines added for clarity):

>>> from django.template import *
>>> t = Template('''{% cycle "Hello, how are you?" "Fine!" %}''')

/home/carsten/.virtualenvs/Ze/local/lib/python2.7/site-packages/django/template/base.py:290: RemovedInDjango18Warning: 'The `cycle` template tag is changing to escape its arguments; the non-autoescaping version is deprecated. Load it from the `future` tag library to start using the new behavior.
  compiled_result = compile_func(self, token)

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/carsten/.virtualenvs/Ze/local/lib/python2.7/site-packages/django/template/base.py", line 132, in __init__
    self.nodelist = compile_string(template_string, origin)
  File "/home/carsten/.virtualenvs/Ze/local/lib/python2.7/site-packages/django/template/base.py", line 162, in compile_string
    return parser.parse()
  File "/home/carsten/.virtualenvs/Ze/local/lib/python2.7/site-packages/django/template/base.py", line 290, in parse
    compiled_result = compile_func(self, token)
  File "/home/carsten/.virtualenvs/Ze/local/lib/python2.7/site-packages/django/template/defaulttags.py", line 648, in cycle
    values = [parser.compile_filter(arg) for arg in args[1:]]
  File "/home/carsten/.virtualenvs/Ze/local/lib/python2.7/site-packages/django/template/base.py", line 372, in compile_filter
    return FilterExpression(token, self)
  File "/home/carsten/.virtualenvs/Ze/local/lib/python2.7/site-packages/django/template/base.py", line 588, in __init__
    "from '%s'" % (token[upto:], token))
TemplateSyntaxError: Could not parse the remainder: 'Hello"' from '""Hello"'

(Probably not relevant, but fyi, this happens with or without {% load cycle from future %}.)

Change History (7)

comment:1 by Tim Graham, 9 years ago

Owner: changed from nobody to Tim Graham
Status: newassigned
Triage Stage: UnreviewedAccepted

I confirmed the suspection on the mailing list that this is caused by those particular arguments being parsed using the legacy syntax. I'll use this as an excuse to deprecate that syntax.

comment:2 by Tim Graham, 9 years ago

Has patch: set

comment:3 by Collin Anderson, 9 years ago

I agree deprecation makes sense.

comment:4 by Baptiste Mispelon, 9 years ago

Triage Stage: AcceptedReady for checkin

LGTM

comment:5 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In c36b60836be9e78ab877566cc43dc03960ce944d:

Fixed #24451 -- Deprecated comma-separated {% cycle %} syntax.

comment:6 by Tim Graham <timograham@…>, 9 years ago

In 47201371:

Refs #24451 -- Corrected Django version for {% cycle %} deprecation.

comment:7 by Tim Graham <timograham@…>, 9 years ago

In 27b23217:

Refs #24451 -- Removed comma-separated {% cycle %} syntax per deprecation timeline.

Note: See TracTickets for help on using tickets.
Back to Top