3

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.

Abid A
  • 7,588
  • 4
  • 32
  • 32

2 Answers2

2

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
Community
  • 1
  • 1
Dr. Jan-Philip Gehrcke
  • 33,287
  • 14
  • 85
  • 130
0

You might give the answer to this question a try. Seems to do what you need.

Community
  • 1
  • 1
Thomas Kremmel
  • 14,575
  • 26
  • 108
  • 177