Django 'ascii' codec can't encode character -
in django want use simple template tag truncate data.
this have far:
@register.filter(name='truncate_simple') def truncate_char_to_space(value, arg): """ truncates string after given length. """ data = str(value) if len(value) < arg: return data if data.find(' ', arg, arg+5) == -1: return data[:arg] + '...' else: return data[:arg] + data[arg:data.find(' ', arg)] + '...'
but when use following error:
{{ item.content|truncate_simple:5 }}
error:
'ascii' codec can't encode character u'\u2013' in position 84: ordinal not in range(128)
error on line starting data = str(value)
why?
try use unicode() convert value (instead of str()):
data = unicode(value)
Comments
Post a Comment