我有时间验证一个 6 位数字:
# forms.py
class TheForm(forms.Form):
code = forms.RegexField(regex=r'^\d{6}$')
# tests.py
class TheFormTestCase(TestCase):
def test_the_form(self):
form = TheForm(initial={'code': '123456'})
self.assertTrue(form.is_valid(),
'Form should accept a string of 6 characters '
'that are digits')
我的测试用例返回无效。有人可以指出我做错了什么吗?