[Django]-Is there a way to replace Django's smart_str with a Python native solution?

4👍

I replaced it with this dummy function that apply unicode(x).encode("utf-8") if the string is unicode, and convert it to str if it’s a number:

def smart_str(x):
    if isinstance(x, unicode):
        return unicode(x).encode("utf-8")
    elif isinstance(x, int) or isinstance(x, float):
        return str(x)
    return x
👤Assem

Leave a comment