2

I'm trying to read an email-id value using request.POST.get(). If the post data contains email-id with a '+' symbol, like "example+something@gmail.com", it gets read as

"example something@gmail.com".

I know this is happening because the + symbol is getting decoded as space, but how do I prevent this from happening in this scenario?

Arun Nair
  • 305
  • 2
  • 9
  • 1
    I'm guessing you want to url-encode your strings something like: https://stackoverflow.com/questions/14547491/url-encoding-on-django-template?answertab=votes#tab-top – MLavrentyev Jul 08 '20 at 14:11
  • 1
    @MLavrentyev That helped! Couldn't use urlencode filter as shown in the answer but I did something similar using js. I'll post it as an answer. – Arun Nair Jul 08 '20 at 14:46

1 Answers1

1

Solved it! The post data was not being urlencoded before being sent. For my scenario, since I was using Javascript XMLHttpRequest to post data, I simply replaced the "+" symbol with "%2B" using the js replace() function.

Another way according to https://stackoverflow.com/a/14830517/5918981 is to use encodeURIComponent()

Arun Nair
  • 305
  • 2
  • 9