我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用django.shortcuts()。
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)