from django.http import QueryDict
QueryDict('query=c++')
Why the output is, <QueryDict: {u'query': [u'c ']}>
Does querydict remove the + symbol from the string? I am using Python 2.7.17 and Django version 1.10.4.
from django.http import QueryDict
QueryDict('query=c++')
Why the output is, <QueryDict: {u'query': [u'c ']}>
Does querydict remove the + symbol from the string? I am using Python 2.7.17 and Django version 1.10.4.
When you instantiate QueryDict class, it invoke parse_qs to parse the query_string(In this case it's 'query=c++'). See the django QueryDict implementation here.
>>> from urllib.parse import parse_qsl
>>> parse_qsl("query=c++")
[('query', 'c ')]
So why the result has space instead of +?. Well the answer is within the query string, the plus sign is reserved as shorthand notation for a space. Therefore, real plus signs must be encoded.
>>> from urllib.parse import parse_qsl
>>> parse_qsl("query=c%2B%2B")
[('query', 'c++')]