diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 6b1be37..260b9a5 100644
a
|
b
|
class CheckboxInput(Widget):
|
528 | 528 | values = {'true': True, 'false': False} |
529 | 529 | if isinstance(value, six.string_types): |
530 | 530 | value = values.get(value.lower(), value) |
531 | | return value |
| 531 | return bool(value) |
532 | 532 | |
533 | 533 | def _has_changed(self, initial, data): |
534 | 534 | # Sometimes data or initial could be None or '' which should be the |
diff --git a/tests/regressiontests/forms/tests/forms.py b/tests/regressiontests/forms/tests/forms.py
index a8a28ba..1c83ed0 100644
a
|
b
|
class FormsTestCase(TestCase):
|
269 | 269 | f = SignupForm({'email': 'test@example.com', 'get_spam': 'false'}, auto_id=False) |
270 | 270 | self.assertHTMLEqual(str(f['get_spam']), '<input type="checkbox" name="get_spam" />') |
271 | 271 | |
| 272 | # A value of '0' should be interpreted as a True value (#16820) |
| 273 | f = SignupForm({'email': 'test@example.com', 'get_spam': '0'}) |
| 274 | self.assertTrue(f.is_valid()) |
| 275 | self.assertTrue(f.cleaned_data.get('get_spam')) |
| 276 | |
272 | 277 | def test_widget_output(self): |
273 | 278 | # Any Field can have a Widget class passed to its constructor: |
274 | 279 | class ContactForm(Form): |
diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py
index 3ea42cf..9924f3b 100644
a
|
b
|
class FormsWidgetTestCase(TestCase):
|
228 | 228 | # checkboxes). |
229 | 229 | self.assertFalse(w.value_from_datadict({}, {}, 'testing')) |
230 | 230 | |
| 231 | value = w.value_from_datadict({'testing': '0'}, {}, 'testing') |
| 232 | self.assertTrue(isinstance(value, bool)) |
| 233 | self.assertTrue(value) |
| 234 | |
231 | 235 | self.assertFalse(w._has_changed(None, None)) |
232 | 236 | self.assertFalse(w._has_changed(None, '')) |
233 | 237 | self.assertFalse(w._has_changed('', None)) |