Decoding unicode from Javascript in Python & Django

On a website I have the word pluș sent via POST to a Django view. It is sent as plu%25C8%2599. So I took that string and tried to figure out a way how to make %25C8%2599 back into ș.

I tried decoding the string like this:

from urllib import unquote_plus
s = "plu%25C8%2599"
print unquote_plus(unquote_plus(s).decode('utf-8'))

The result i get is pluÈ which actually has a length of 5, not 4.

How can I get the original string pluș after it's encoded ?


I managed to do it like this

def js_unquote(quoted):
  quoted = quoted.encode('utf-8')
  quoted = unquote_plus(unquote_plus(quoted)).decode('utf-8')
  return quoted

It looks weird but works the way I needed it.


URL-decode twice, then decode as UTF-8.

Need Your Help

Fitting a large background image to fit in a small div

html css

So I have an image which is 700px width which is what I'm using as a background image in a div which is 200px width.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.