summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRomain DA COSTA VIEIRA <romain.da-costa-vieira@michelin.com>2025-09-24 14:55:54 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-09-26 16:47:46 +0200
commit1cb76b90e844308ae21d24115311bc354efe56e6 (patch)
tree310df25cbfe4696bc8fa3d3842977111aee8dec8
parent7894776bc99e42f20e0919fc9027e6db542957d5 (diff)
Fixed #36142 -- Made Http404 messages in *_or_404() shortcuts translatable.
-rw-r--r--django/shortcuts.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/django/shortcuts.py b/django/shortcuts.py
index 6274631dba..4eeb39121e 100644
--- a/django/shortcuts.py
+++ b/django/shortcuts.py
@@ -13,6 +13,7 @@ from django.http import (
from django.template import loader
from django.urls import NoReverseMatch, reverse
from django.utils.functional import Promise
+from django.utils.translation import gettext as _
def render(
@@ -90,7 +91,10 @@ def get_object_or_404(klass, *args, **kwargs):
return queryset.get(*args, **kwargs)
except queryset.model.DoesNotExist:
raise Http404(
- "No %s matches the given query." % queryset.model._meta.object_name
+ # Translators: %s is the name of a model, e.g. "No City matches the
+ # given query."
+ _("No %s matches the given query.")
+ % queryset.model._meta.object_name
)
@@ -108,7 +112,9 @@ async def aget_object_or_404(klass, *args, **kwargs):
try:
return await queryset.aget(*args, **kwargs)
except queryset.model.DoesNotExist:
- raise Http404(f"No {queryset.model._meta.object_name} matches the given query.")
+ raise Http404(
+ _("No %s matches the given query.") % queryset.model._meta.object_name
+ )
def get_list_or_404(klass, *args, **kwargs):
@@ -131,7 +137,7 @@ def get_list_or_404(klass, *args, **kwargs):
obj_list = list(queryset.filter(*args, **kwargs))
if not obj_list:
raise Http404(
- "No %s matches the given query." % queryset.model._meta.object_name
+ _("No %s matches the given query.") % queryset.model._meta.object_name
)
return obj_list
@@ -149,7 +155,9 @@ async def aget_list_or_404(klass, *args, **kwargs):
)
obj_list = [obj async for obj in queryset.filter(*args, **kwargs)]
if not obj_list:
- raise Http404(f"No {queryset.model._meta.object_name} matches the given query.")
+ raise Http404(
+ _("No %s matches the given query.") % queryset.model._meta.object_name
+ )
return obj_list