mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #26281 -- Added a helpful error message for an invalid format specifier to dateformat.format().
This commit is contained in:
@@ -767,10 +767,10 @@ def time(value, arg=None):
|
||||
return ''
|
||||
try:
|
||||
return formats.time_format(value, arg)
|
||||
except AttributeError:
|
||||
except (AttributeError, TypeError):
|
||||
try:
|
||||
return time_format(value, arg)
|
||||
except AttributeError:
|
||||
except (AttributeError, TypeError):
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
@@ -34,6 +34,11 @@ class Formatter(object):
|
||||
pieces = []
|
||||
for i, piece in enumerate(re_formatchars.split(force_text(formatstr))):
|
||||
if i % 2:
|
||||
if type(self.data) is datetime.date and hasattr(TimeFormat, piece):
|
||||
raise TypeError(
|
||||
"The format for date objects may not contain "
|
||||
"time-related format specifiers (found '%s')." % piece
|
||||
)
|
||||
pieces.append(force_text(getattr(self, piece)()))
|
||||
elif piece:
|
||||
pieces.append(re_escaped.sub(r'\1', piece))
|
||||
|
||||
Reference in New Issue
Block a user