This works fine for me in Python 2.7, if name is the unicode() value:
>>> ord(u'\u4e00') < 0x4e00 False >>> ord(u'\u4dff') < 0x4e00 True
You do not need to use ord here if you are comparing a character directly with unicode values:
>>> u'\u4e00' < u'\u4e00' False >>> u'\u4dff' < u'\u4e00' True
The data from the incoming request has not yet been decoded to Unicode, you need to do this first. Explicitly set the accept-charset attribute in the form tag to ensure that the browser uses the correct encoding:
<form accept-charset="utf-8" action="...">
then decode the server side data:
name = self.request.get('name').decode('utf8')
Martijn pieters
source share