Skip to main content

get_list_or_404

Use filter() to return a list of objects, or raise an Http404 exception if the list is empty.

klass may be a Model, Manager, or QuerySet object. All other passed arguments and keyword arguments are used in the filter() query.

def get_list_or_404(
klass: Model, Manager, or QuerySet,
*args: any,
**kwargs: any
) - > list

Use filter() to return a list of objects, or raise an Http404 exception if the list is empty.

Parameters

NameTypeDescription
klassModel, Manager, or QuerySetThe Model class, Manager, or QuerySet instance from which to retrieve the objects.
*argsanyPositional arguments passed directly to the filter() method to define query constraints.
**kwargsanyKeyword arguments passed directly to the filter() method to define query constraints.

Returns

TypeDescription
listA list of model instances matching the provided query criteria.