python 约束子类必有方法

class BaseAuthentication:
    """
    All authentication classes should extend BaseAuthentication.
    """

    def authenticate(self, request):
        """
        如果子类继承BaseAuthentication,就必须有authenticate方法,不然报错
        """
        raise NotImplementedError(".authenticate() must be overridden.")
posted @ 2022-10-01 08:35  Sherwin_szw  阅读(25)  评论(0编辑  收藏  举报