Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Template For Loop Over request.META Dictionary

I am trying to loop over a dictionary, specifically the request object's meta property. It is a dictionary, but the following code is treating it like it is a list of strings. How can I do this correctly?

EDIT: I found that if I replace request.META with request.META.items, this works, but why does the following not work? Is it not a dict?

{% for a, b in request.META %}
    {{ a }}: {{ b }}
{% endfor %}

Yields (this is shortened for brevity):

G: D
w: s
R: U
H: T
G: N
...
L: S
R: E
H: T
P: A

Whereas:

{{request.META}}

Yields:

{'GDM_KEYBOARD_LAYOUT': 'us',
'wsgi.multiprocess': False,
'RUN_MAIN': 'true',
'HTTP_COOKIE': 'sessionid=...
...
...6:*.spx=00;36:*.xspf=00;36:',
'REMOTE_HOST': '',
'HTTP_ACCEPT_ENCODING': 'gzip,deflate',
'PATH_INFO': u'/'} 
like image 278
kzh Avatar asked Nov 20 '25 02:11

kzh


1 Answers

Replacing request.META with request.META.items works.

like image 186
kzh Avatar answered Nov 22 '25 17:11

kzh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!