0

I am writing a few REST APIs.

In one of those I want to know order in which the parameters were mentioned in the query string.

Right now, I am accessing query params using

request.params

This returns a nested-multi-dict. But I don't think the keys are ordered correctly.

Any other way, I can get ordered-dict?

Thanks in advance !!

yashdosi
  • 1,186
  • 1
  • 18
  • 40

1 Answers1

1

request.params, request.GET and request.POST are ordered MultiDicts, so you can use items() method:

from pyramid.request import Request

req = Request.blank('http://gdzies.w.pl/ala/ma/kota?q=1&q=2&w=3&w=4&q=5&a=0')
print req.params.items()

The output:

[(u'q', u'1'), (u'q', u'2'), (u'w', u'3'), (u'w', u'4'), (u'q', u'5'), (u'a', u'0')]
Codringher
  • 141
  • 4