"Variables and attributes may not begin with underscores" error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

"Variables and attributes may not begin with underscores" error

Raffaele Salmaso-2
Hi,
anyone knows the rationale for forbidding variables and attributes with an initial underscore in django templates?
This limitation is here from day 0 
and docs doesn't mention it (or simply I can't google it)

I've removed this check and it seem fine for the empirical tests

If there is no objection would be ok to remove this limitation?

Thaks

--

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CABgH4Js0kfnxcEggt%3DTF1Q3CH%3D%2Bp5DHF3YWjN%2BAHe_DrrMLM0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: "Variables and attributes may not begin with underscores" error

Gregory Kaleka
The docs do mention it on the more complete template api page, though there isn't an explanation as to the reason. I would say it should at least be added to the template docs you link to.

On Friday, June 29, 2018 at 2:28:41 PM UTC-7, Raffaele Salmaso wrote:
Hi,
anyone knows the rationale for forbidding variables and attributes with an initial underscore in django templates?
This limitation is here from day 0 
<a href="https://github.com/django/django/blob/ed114e15106192b22ebb78ef5bf5bce72b419d13/django/core/template.py#L261" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fed114e15106192b22ebb78ef5bf5bce72b419d13%2Fdjango%2Fcore%2Ftemplate.py%23L261\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGa-Yry_j6tCuyaVfGK8OR0zCXahw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fed114e15106192b22ebb78ef5bf5bce72b419d13%2Fdjango%2Fcore%2Ftemplate.py%23L261\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGa-Yry_j6tCuyaVfGK8OR0zCXahw&#39;;return true;">https://github.com/django/django/blob/ed114e15106192b22ebb78ef5bf5bce72b419d13/django/core/template.py#L261
and docs doesn't mention it (or simply I can't google it)
<a href="https://docs.djangoproject.com/en/dev/ref/templates/language/#variables" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2Fdev%2Fref%2Ftemplates%2Flanguage%2F%23variables\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHH6yJkSzFfn07lPUZty3rpq2BO0A&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2Fdev%2Fref%2Ftemplates%2Flanguage%2F%23variables\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHH6yJkSzFfn07lPUZty3rpq2BO0A&#39;;return true;">https://docs.djangoproject.com/en/dev/ref/templates/language/#variables

I've removed this check and it seem fine for the empirical tests
<a href="https://github.com/django/django/blob/master/django/template/base.py#L786" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fmaster%2Fdjango%2Ftemplate%2Fbase.py%23L786\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHAEy9kndOomRKAS8Kp9_8SXV_ViA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fmaster%2Fdjango%2Ftemplate%2Fbase.py%23L786\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHAEy9kndOomRKAS8Kp9_8SXV_ViA&#39;;return true;">https://github.com/django/django/blob/master/django/template/base.py#L786

If there is no objection would be ok to remove this limitation?

Thaks

--
| Raffaele Salmaso
| <a href="https://salmaso.org" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fsalmaso.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEDkdSmmUpZZGalSHiAeD1f1T7ZFA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fsalmaso.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEDkdSmmUpZZGalSHiAeD1f1T7ZFA&#39;;return true;">https://salmaso.org
| <a href="https://bitbucket.org/rsalmaso" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fbitbucket.org%2Frsalmaso\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbJhXNuq88BPM7dQLQ0pk55q1WUg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fbitbucket.org%2Frsalmaso\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbJhXNuq88BPM7dQLQ0pk55q1WUg&#39;;return true;">https://bitbucket.org/rsalmaso
| <a href="https://github.com/rsalmaso" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Frsalmaso\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHecqstofEdtqwWhlb-67uc3PkFaQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Frsalmaso\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHecqstofEdtqwWhlb-67uc3PkFaQ&#39;;return true;">https://github.com/rsalmaso

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/9549cb1f-0f6b-421c-a57c-44876b86f5d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: "Variables and attributes may not begin with underscores" error

Tim Graham-2
I think the reason is that underscore-prefixed attributes are generally considered to be private. Accessing them in templates doesn't seem like good practice.

On Friday, June 29, 2018 at 6:44:56 PM UTC-4, Gregory Kaleka wrote:
<a href="https://docs.djangoproject.com/en/dev/ref/templates/api/#variables-and-lookups" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2Fdev%2Fref%2Ftemplates%2Fapi%2F%23variables-and-lookups\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH7G0Vr2f9bJb3rj1tnNXLaNLrRXA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2Fdev%2Fref%2Ftemplates%2Fapi%2F%23variables-and-lookups\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH7G0Vr2f9bJb3rj1tnNXLaNLrRXA&#39;;return true;">The docs do mention it on the more complete template api page, though there isn't an explanation as to the reason. I would say it should at least be added to the template docs you link to.

On Friday, June 29, 2018 at 2:28:41 PM UTC-7, Raffaele Salmaso wrote:
Hi,
anyone knows the rationale for forbidding variables and attributes with an initial underscore in django templates?
This limitation is here from day 0 
<a href="https://github.com/django/django/blob/ed114e15106192b22ebb78ef5bf5bce72b419d13/django/core/template.py#L261" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fed114e15106192b22ebb78ef5bf5bce72b419d13%2Fdjango%2Fcore%2Ftemplate.py%23L261\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGa-Yry_j6tCuyaVfGK8OR0zCXahw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fed114e15106192b22ebb78ef5bf5bce72b419d13%2Fdjango%2Fcore%2Ftemplate.py%23L261\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGa-Yry_j6tCuyaVfGK8OR0zCXahw&#39;;return true;">https://github.com/django/django/blob/ed114e15106192b22ebb78ef5bf5bce72b419d13/django/core/template.py#L261
and docs doesn't mention it (or simply I can't google it)
<a href="https://docs.djangoproject.com/en/dev/ref/templates/language/#variables" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2Fdev%2Fref%2Ftemplates%2Flanguage%2F%23variables\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHH6yJkSzFfn07lPUZty3rpq2BO0A&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2Fdev%2Fref%2Ftemplates%2Flanguage%2F%23variables\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHH6yJkSzFfn07lPUZty3rpq2BO0A&#39;;return true;">https://docs.djangoproject.com/en/dev/ref/templates/language/#variables

I've removed this check and it seem fine for the empirical tests
<a href="https://github.com/django/django/blob/master/django/template/base.py#L786" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fmaster%2Fdjango%2Ftemplate%2Fbase.py%23L786\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHAEy9kndOomRKAS8Kp9_8SXV_ViA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fblob%2Fmaster%2Fdjango%2Ftemplate%2Fbase.py%23L786\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHAEy9kndOomRKAS8Kp9_8SXV_ViA&#39;;return true;">https://github.com/django/django/blob/master/django/template/base.py#L786

If there is no objection would be ok to remove this limitation?

Thaks

--
| Raffaele Salmaso
| <a href="https://salmaso.org" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fsalmaso.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEDkdSmmUpZZGalSHiAeD1f1T7ZFA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fsalmaso.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEDkdSmmUpZZGalSHiAeD1f1T7ZFA&#39;;return true;">https://salmaso.org
| <a href="https://bitbucket.org/rsalmaso" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fbitbucket.org%2Frsalmaso\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbJhXNuq88BPM7dQLQ0pk55q1WUg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fbitbucket.org%2Frsalmaso\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbJhXNuq88BPM7dQLQ0pk55q1WUg&#39;;return true;">https://bitbucket.org/rsalmaso
| <a href="https://github.com/rsalmaso" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Frsalmaso\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHecqstofEdtqwWhlb-67uc3PkFaQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Frsalmaso\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHecqstofEdtqwWhlb-67uc3PkFaQ&#39;;return true;">https://github.com/rsalmaso

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/084d24b9-4c30-4ed9-ac65-80d132ec16f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.