Python django 模块,shortcuts() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用django.shortcuts()

项目:django-rest-framework-client    作者:qvantel    | 项目源码 | 文件源码
def get_object_or_404(klass, *args, **kwargs):
    """
    Similar to django.shortcuts.get_object_or_404 but it also supports klass argument to be of type
    restframework.Model or PartiallyFiltered
    """
    if isinstance(klass, (ModelBase, PartiallyFiltered)):
        partially_filtered = klass if isinstance(klass, PartiallyFiltered) else klass.objects.all()
        model = partially_filtered.model
        try:
            return partially_filtered.get(*args, **kwargs)
        except model.DoesNotExist:
            raise Http404('No %s matches the given query.' % model._meta.object_name)
    else:
        return django_get_object_or_404(klass, *args, **kwargs)