[Django]-Implementing accent insensitive search on django using sqlite

-1👍

Try using the unicodedata package. Here’s an example for Python 3:

import unicodedata

unicodedata.normalize('NFD', 'répertoire').encode('ascii', 'ignore')

Or, for Python 2.7:

import unicodedata

unicodedata.normalize('NFD', u'répertoire').encode('ascii', 'ignore')

Either of these will output:

'repertoire'

Simply replace répertoire with your string. NFD is a form of normalization. You can read more on the different forms of normalization here:

https://docs.python.org/3/library/unicodedata.html#unicodedata.normalize
https://docs.python.org/2/library/unicodedata.html#unicodedata.normalize

Good luck!

Leave a comment