Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
Django QueryDict How to ensure that the "plus" does not disappear in the QueryDict?

How to ensure that the "plus" does not disappear in the QueryDict?

I am trying to parse the received get-query into a dict:

from urllib.parse import quote_plus

my_non_safe_string = "test=1+1" # This example, the string can be anything. (in GET query format)
QueryDict(my_non_safe_string)
out: <QueryDict: {'test': ['1 1']}>

my_safe_string = quote_plus("test=1+1") # 'test%3D1%2B1'
out: <QueryDict: {'test=1+1': ['']}>

I would like to get the following result:

<QueryDict: {'test=1+1': ['1+1']}>
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You need to percentage encode the plus, by use quote_plus you also encode the equal sign (=) and therefore the QueryDict can not parse it effectively:

my_safe_string = f'test={quote_plus("1+1")}'

this produces:

>>> from urllib.parse import quote_plus
>>> my_safe_string = f'test={quote_plus("1+1")}'
>>> QueryDict(my_safe_string)
<QueryDict: {'test': ['1+1']}>

If it is unclear if the key contains any characters that should be escaped, you can use:

key = 'test'
value = '1+1'
my_safe_string = f'{ quote_plus(key) }={ quote_plus(value) }'
over 4 years ago · Santiago Trujillo Report

0

How about this?

In [1]: from django.http import QueryDict

In [2]: from urllib.parse import quote_plus

In [3]: key = quote_plus("test=1+1")

In [4]: value = quote_plus("1+1")

In [5]: query_str = f"{key}={value}"

In [6]: QueryDict(query_str)
Out[6]: <QueryDict: {'test=1+1': ['1+1']}>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!