diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 64646d58c..4263adcef 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -318,6 +318,9 @@ class HTMLFormRenderer(BaseRenderer): style['template_pack'] = parent_style.get('template_pack', self.template_pack) style['renderer'] = self + # Get a clone of the field with text-only value representation. + field = field.as_form_field() + if style.get('input_type') == 'datetime-local' and isinstance(field.value, six.text_type): field.value = field.value.rstrip('Z') diff --git a/rest_framework/utils/serializer_helpers.py b/rest_framework/utils/serializer_helpers.py index b751a3588..9d2f70c88 100644 --- a/rest_framework/utils/serializer_helpers.py +++ b/rest_framework/utils/serializer_helpers.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import collections -from rest_framework.compat import OrderedDict, unicode_to_repr +from rest_framework.compat import OrderedDict, force_text, unicode_to_repr class ReturnDict(OrderedDict): @@ -54,6 +54,7 @@ class BoundField(object): """ def __init__(self, field, value, errors, prefix=''): self._field = field + self._prefix = prefix self.value = value self.errors = errors self.name = prefix + self.field_name @@ -70,6 +71,9 @@ class BoundField(object): self.__class__.__name__, self.value, self.errors )) + def as_form_field(self): + return BoundField(self._field, force_text(self.value), self.errors, self._prefix) + class NestedBoundField(BoundField): """