#30310: New HTTPRequest.headers not usable in templates because of hyphens
-------------------------------------+-------------------------------------
Reporter: Mark Tranchant | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 2.2
Severity: Normal | Resolution:
Keywords: request headers | Triage Stage: Accepted
hyphen template |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mark Tranchant):
Replying to [comment:3 Carlton Gibson]:
> Hi Mark.
>
> The default answer for the template later is to implement a filter that
will let you do the lookup with a string.
([https://stackoverflow.com/questions/8000022/django-template-how-to-look-
up-a-dictionary-value-with-a-variable StackOverflow has lots of
examples].)
>
> Maybe we could allow this by adding a `key.replace('_', '-')`
implementing `HttpHeaders.__getitem__()`? (Probably worth seeing what a
patch there looks like anyway.)
>
> (This instead of storing the items twice in the underlying store.)
Yes, I found the filter solution. Whilst that's fine for fixing up user-
generated problems, this new problem comes out-of-the-box in 2.2. It feels
like there should be a solution along with it.
Your suggestion is much better than mine. New patch added that allows
`request.headers['foo-bar']` to be looked up in templates as `{{
request.headers.foo_bar }}` without inelegant double storage.
--
Ticket URL: <https://code.djangoproject.com/ticket/30310#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/071.41eb23c6b5e22d6c5af3ffd2cc8d7bcb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.