diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py index c3e4b09d93..076845427d 100644 --- a/django/newforms/widgets.py +++ b/django/newforms/widgets.py @@ -161,8 +161,11 @@ class DateTimeInput(Input): self.format = format def render(self, name, value, attrs=None): - return super(DateTimeInput, self).render(name, - value.strftime(self.format), attrs) + if value is None: + value = '' + elif hasattr(value, 'strftime'): + value = value.strftime(self.format) + return super(DateTimeInput, self).render(name, value, attrs) class CheckboxInput(Widget): def __init__(self, attrs=None, check_test=bool): diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py index 032f3cbb91..cb1d084631 100644 --- a/tests/regressiontests/forms/widgets.py +++ b/tests/regressiontests/forms/widgets.py @@ -855,6 +855,8 @@ u'>> w = DateTimeInput() +>>> w.render('date', None) +u'' >>> d = datetime.datetime(2007, 9, 17, 12, 51, 34, 482548) >>> print d 2007-09-17 12:51:34.482548