With my current reputation, I have no way to comment, so I choose the answer that refers to the comments for the sample code in the response of Prashant Gaura (thanks, Gaura - it was useful!) - his example is for python2, since python3 has no method
unicode
,
The replacement below for the function
get_prep_value (self, value):
should work with Django working with python3 (I will use this code soon - until I tested it). Please note that I am passing parameters
encoding = 'utf-8', errors = 'ignore'
at
decode ()
and
unicode () methods
. The encoding should match your Django settings.py configuration, and the transfer
errors = 'ignore'
is optional (and can lead to loss of data without displaying messages instead of an exception that, in rare cases, incorrectly configures django).
import sys
...
def get_prep_value (self, value):
if value is None:
return value
if sys.version_info [0]> = 3:
if isinstance (out_data, type (b``)):
return value.decode (encoding = 'utf-8', errors = 'ignore')
else:
if isinstance (out_data, type (b``)):
return unicode (value, encoding = 'utf-8', errors = 'ignore')
return str (value)
...
Oleg Artemev Jul 26 '18 at 18:31 2018-07-26 18:31
source share