python – django testCase中的POST日期值
发布时间:2020-12-20 13:46:08 所属栏目:Python 来源:网络整理
导读:我正在尝试编写一个测试来注册用户.我无法获得要验证的表单,因为我无法弄清楚如何向表单提交有效日期.这是违规代码: class AccountManagementTest(TestCase): def test_signup(self): response = self.client.post(reverse('register'),{ 'first_name': 'Ga
我正在尝试编写一个测试来注册用户.我无法获得要验证的表单,因为我无法弄清楚如何向表单提交有效日期.这是违规代码:
class AccountManagementTest(TestCase): def test_signup(self): response = self.client.post(reverse('register'),{ 'first_name': 'Gandalf','last_name': 'TheGrey','email': 'gandalf@me.com','password1': 'SauronSucks','password2': 'SauronSucks','birthdate': datetime(1956,1,1),'tos': True}) 之后我可以输出response.content,表单中的错误是“请输入有效日期”.我没有在表格中覆盖生日的清洁方法.这是表单中日期字段的声明: birthdate = forms.DateField( widget=SelectDateWidget( years=range(this_year-90,this_year-12)[::-1]),required=True,) 我怎么发送有效日期? 解决方法
您需要传递与默认值
input_formats 之一匹配的日期的字符串表示形式:
['%Y-%m-%d',# '2006-10-25' '%m/%d/%Y',# '10/25/2006' '%m/%d/%y'] # '10/25/06' 在你的情况下,它可能是,例如: 'birthdate': '1956-01-01' (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |