2020年5月13日水曜日

Django Object of type 'UUID' is not JSON serializable

Django のpkをuuid に変えたところ、

ERROR :   Object of type 'UUID' is not JSON serializable

下記で解消。

vi models.py
#
# Fixed for the following error by takahab
# ERROR: Object of type 'UUID' is not JSON serializable
#
#--------------------ここから-------------------------------
from json import JSONEncoder
from uuid import UUID
JSONEncoder_olddefault = JSONEncoder.default
def JSONEncoder_newdefault(self, o):
    if isinstance(o, UUID): return str(o)
    return JSONEncoder_olddefault(self, o)
JSONEncoder.default = JSONEncoder_newdefault
#-----------------ここまで----------------------------------

Rocky Linux9.8 Docker インストール

# cat /etc/redhat-release Rocky Linux release 9.8 (Blue Onyx) # dnf remove docker docker-client  docker-client-latest  docker-common  docker...