mixins.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:adhocracy4 作者: liqd 项目源码 文件源码
def _get_object(self, cls, attr):
        # CreateView supplies a defect get_object method and has to be excluded
        if hasattr(self, 'get_object') \
                and not isinstance(self, generic.CreateView):
            try:
                object = self.get_object()
                if isinstance(object, cls):
                    return object

                if hasattr(object, attr):
                    return getattr(object, attr)
            except Http404:
                return None
            except AttributeError:
                return None

        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号