django自定义异常

from rest_framework.exceptions import APIException

class ServiceUnavailable(APIException):
    status_code = 201
    default_detail = {"username": "root", "msg": "添加用户成功"}
    default_code = "service_unavaliable"
    
class TestView(APIView):
    def get(self,request):
        raise ServiceUnavailable()

猜你喜欢

转载自www.cnblogs.com/xujunkai/p/12435015.html