UUID('…') is not JSON serializable

前端 未结 4 1361
生来不讨喜
生来不讨喜 2020-12-05 23:19

I get this error when i try to pass the UUID attribute to url parameter.

urlpatterns = [
    url(r\'^historia-clinica/(?P[W\\d\\-]+)/$\', ClinicH         


        
4条回答
  •  青春惊慌失措
    2020-12-05 23:44

    I use convert function for this, it is simple and clean.

    import json
    from uuid import UUID
    def uuid_convert(o):
            if isinstance(o, UUID):
                return o.hex
    
    json.dumps(users,indent=4,default=uuid_convert)
    

提交回复
热议问题