Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decoding querystring parameter in Django view

I have a search form in my app that uses a jQuery autocomplete plugin. The plugin sends over the suggested item after running the querystring through encodeURI(q).

So an item like Johnny's sports comes to my view as Johnny's sports

How do I decode the string back to Johnny's Sports so I can query the database?

I've tried several urllib functions that have been suggested in other posts but I think I'm seriously misunderstanding how they work because I'm not seeing it work.

Any help is greatly appreciated.

like image 688
Abid A Avatar asked Nov 16 '25 17:11

Abid A


1 Answers

Python's standardlib contains the HTMLParser. It can perform decoding of escaped HTML entities, as noted in this answer: https://stackoverflow.com/a/2087433/145400

>>> import HTMLParser
>>> h = HTMLParser.HTMLParser()
>>> print h.unescape('Johnny's sports')
Johnny's sports
like image 196
Dr. Jan-Philip Gehrcke Avatar answered Nov 19 '25 09:11

Dr. Jan-Philip Gehrcke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!