get_object_or_404
Use get() to return an object, or raise an Http404 exception if the object does not exist. klass may be a Model, Manager, or QuerySet object. All other passed arguments and keyword arguments are used in the get() query. Like with QuerySet.get(), MultipleObjectsReturned is raised if more than one object is found.
def get_object_or_404(
klass: Model, Manager, or QuerySet,
*args: Any,
**kwargs: Any
) - > Model instance
Use get() to return an object, or raise an Http404 exception if the object does not exist.
Parameters
| Name | Type | Description |
|---|---|---|
| klass | Model, Manager, or QuerySet | The model class, manager, or queryset from which to retrieve the object. |
| *args | Any | Positional arguments passed directly to the get() method of the queryset. |
| **kwargs | Any | Lookup parameters used to filter the queryset, passed directly to the get() method. |
Returns
| Type | Description |
|---|---|
Model instance | The single model instance retrieved from the database matching the provided query criteria. |