1from django.shortcuts import get_object_or_404
2
3def my_view(request):
4 obj = get_object_or_404(MyModel, pk=1)
5
1from django.http import Http404
2
3def my_view(request):
4 my_objects = list(MyModel.objects.filter(published=True))
5 if not my_objects:
6 raise Http404("No MyModel matches the given query.")
7