Saturday, March 28, 2015

Re: QueryDict and its .dict() method - why does it do that?

On Sat, Mar 28, 2015 at 5:37 AM, Stephen J. Butler <stephen.butler@gmail.com> wrote:
Let's be accurate here: what PHP, Rails, jQuery, et al. do is not
"non-standard". There's nothing wrong with their key-value pairs in
the query string. This is further illustrated by the fact that no
browser I am aware of has problems encoding them, and QueryDict has no
problem parsing them (it just doesn't do it with quite the same
result).

Well, there is no adopted standard which says that these query strings are to be interpreted identically:

foo=bar&foo=baz

foo[]=bar&foo[]=baz

(RFC 3986 specifies the syntax of a query string, but not how to interpret it)

Historical practice was that each of these would be interpreted as specifying two values for a particular key, but that the former would specify values for the key "foo" and the latter for the key "foo[]". Then a non-standard convention was adopted by some tools to interpret them identically, as specifying multiple values for the key "foo".

The main issue was jQuery adopted this by default, which in turn has a history of breaking things for users of Django.


Perhaps it would be better to think about this issue as Plain Standard
and Enhanced Standard. Django does the bare basics of what is
required. PHP, Rails, jQuery, et al. go a little further in the
parsing. But there's absolutely nothing wrong with the choice they
made.

There is a problem: the choice they made was incompatible with many pre-existing tools, and with anyone who cared about maintaining easy compatibility with pre-existing tools. Last time I raised the issue with jQuery (five years ago), however, breaking Django and other traditional query string parsing tools by default was considered a wontfix issue on grounds that it's possible to manually set a flag to get the traditional behavior.

That was the last time I bothered trying to interact with the jQuery people. Luckily, I already had good technical reasons for preferring other JS toolkits :)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL13Cg87XXu%2B_Frj%3D_Xdx%2BRChAByO8WTQgDF_XhBA5wgV1UJcA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment