Spaces between argument separator and argument in template filter generate error

150 views
Skip to first unread message

oli...@kidsnote.com

unread,
May 30, 2018, 10:41:22 PM5/30/18
to Django developers (Contributions to Django itself)
In the template filter system now,
spaces between augment separator and augments generate error.
For example, the following template code generates the following error.
{{ value | filter: "arg"}}
TemplateSyntaxError at /
Could not parse the remainder: ': "arg"' from 'value | filter: "arg"'
https://code.djangoproject.com/ticket/29457

What do you think of this ticket?

Adam Johnson

unread,
May 31, 2018, 6:22:52 AM5/31/18
to django-d...@googlegroups.com
I think it's better to be conservative here and leave it as-is, the current syntax has worked for years and this change doesn't really reduce the risk of bugs.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/41376429-949c-4202-9074-5dc0200fc8ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Adam

oli...@kidsnote.com

unread,
May 31, 2018, 7:11:12 AM5/31/18
to Django developers (Contributions to Django itself)
Are there any reasons that not allow spaces between separator and arg?

2018년 5월 31일 목요일 오전 11시 41분 22초 UTC+9, oli...@kidsnote.com 님의 말:

James Bennett

unread,
May 31, 2018, 7:40:58 AM5/31/18
to django-d...@googlegroups.com
On Thu, May 31, 2018 at 1:39 AM, <oli...@kidsnote.com> wrote:
Are there any reasons that not allow spaces between separator and arg?

Every optional variant of template syntax is a potential source of bugs or compatibility issues for the future. And a potential source of confusion when someone is trying to learn by reading code -- why did one developer do it *this* way, while another developer did it *that* way? And another choice every dev team has to make when putting together their style guide, and another option they have to set on their linters, to make sure they get a consistent codebase.

For these reasons, the default position should be "don't add it unless there's a very good reason to". If there is a good reason to add it, please explain so we can understand why you're requesting it.

oli...@kidsnote.com

unread,
May 31, 2018, 8:59:14 PM5/31/18
to Django developers (Contributions to Django itself)
Thank you for your reply.
I understand your opinion well


2018년 5월 31일 목요일 오전 11시 41분 22초 UTC+9, oli...@kidsnote.com 님의 말:
In the template filter system now,

Collin Anderson

unread,
May 31, 2018, 10:06:01 PM5/31/18
to django-d...@googlegroups.com
Maybe it would be worth having a more friendly error message?

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.

Alasdair Nicol

unread,
Jun 1, 2018, 4:59:03 AM6/1/18
to Django developers (Contributions to Django itself)
On Friday, 1 June 2018 03:06:01 UTC+1, Collin Anderson wrote:
Maybe it would be worth having a more friendly error message?


I agree, it would be good to improve the message.

I've also seen users confused by the "could not parse the remainder" message when they forget the spaces around boolean operators, for example:

    {% if foo=='bar' %}

On Thu, May 31, 2018 at 8:59 PM, <oli...@kidsnote.com> wrote:
Thank you for your reply.
I understand your opinion well

2018년 5월 31일 목요일 오전 11시 41분 22초 UTC+9, oli...@kidsnote.com 님의 말:
In the template filter system now,
spaces between augment separator and augments generate error.
For example, the following template code generates the following error.
{{ value | filter: "arg"}}
TemplateSyntaxError at /
Could not parse the remainder: ': "arg"' from 'value | filter: "arg"'
https://code.djangoproject.com/ticket/29457

What do you think of this ticket?

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.

Curtis Maloney

unread,
Jun 1, 2018, 6:21:12 AM6/1/18
to django-d...@googlegroups.com
On 05/31/2018 06:39 PM, oli...@kidsnote.com wrote:
> Are there any reasons that not allow spaces between separator and arg?

My first thought would be that it starts making the syntax looser,
meaning more things that are currently error cases would be accepted as
valid.

Which means mistakes will no longer raise errors.

--
Curtis


> 2018년 5월 31일 목요일 오전 11시 41분 22초 UTC+9, oli...@kidsnote.com
> 의 말:
>
> In the template filter system now,
>
> spaces between augment separator and augments generate error.
> For example, the following template code generates the following error.
>
> {{ value | filter: "arg"}}
>
> TemplateSyntaxError at /
> Could not parse the remainder: ': "arg"' from 'value | filter: "arg"'
>
> https://code.djangoproject.com/ticket/29457
> <https://code.djangoproject.com/ticket/29457>
>
>
> What do you think of this ticket?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-develop...@googlegroups.com
> <mailto:django-develop...@googlegroups.com>.
> To post to this group, send email to django-d...@googlegroups.com
> <mailto:django-d...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/131b5095-c5b7-4492-92fa-e58912ac842a%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/131b5095-c5b7-4492-92fa-e58912ac842a%40googlegroups.com?utm_medium=email&utm_source=footer>.
Message has been deleted
Message has been deleted

oli...@kidsnote.com

unread,
Jun 4, 2018, 10:17:51 PM6/4/18
to Django developers (Contributions to Django itself)
Currently, spaces between filter separator( | ) and filter name is allowed. Also, value name and filter separator.
So, following is allowed.

    {{ value    |    filter:"arg" }}
    {{ value|filter:"arg" }}

But, following is not allowed.

    {{ value|filter: "arg" }}

users are confused by the inconsistency. 

I think that either the error message or syntax should be improved.
Message has been deleted

oli...@kidsnote.com

unread,
Jun 4, 2018, 10:30:03 PM6/4/18
to Django developers (Contributions to Django itself)
filter_raw_string = r"""
^(?P<constant>%(constant)s)|
^(?P<var>[%(var_chars)s]+|%(num)s)|
(?:\s*%(filter_sep)s\s*
(?P<filter_name>\w+)
(?:%(arg_sep)s
(?:
(?P<constant_arg>%(constant)s)|
(?P<var_arg>[%(var_chars)s]+|%(num)s)
)
)?
)""" % {
'constant': constant_string,
'num': r'[-+\.]?\d[\d\.e]*',
'var_chars': r'\w\.',
'filter_sep': re.escape(FILTER_SEPARATOR),
'arg_sep': re.escape(FILTER_ARGUMENT_SEPARATOR),
}

allowing spaces can be done by simply adding \s* after (arg_sep)s

Florian Apolloner

unread,
Jun 6, 2018, 5:03:48 AM6/6/18
to Django developers (Contributions to Django itself)


On Tuesday, June 5, 2018 at 4:30:03 AM UTC+2, oli...@kidsnote.com wrote:
allowing spaces can be done by simply adding \s* after (arg_sep)s

\s is __not__ the regex for spaces

oli...@kidsnote.com

unread,
Jun 6, 2018, 10:44:43 PM6/6/18
to Django developers (Contributions to Django itself)
Sorry my mistake. It means white spaces  character not spaces

2018년 6월 6일 수요일 오후 6시 3분 48초 UTC+9, Florian Apolloner 님의 말:
Reply all
Reply to author
Forward
0 new messages