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
#-----------------ここまで----------------------------------

シャットダウン時の後処理 (shutdown)

# vi /etc/systemd/system/drop.service [Unit] Description= stop httpgwd DefaultDependencies=no Before=shutdown.target RefuseManualStart=true ...