每次请求人们在我的网站上使用该表单时都会收到错误 在DateField上,即使看起来他们的输入很好
birthday = forms.DateField(widget=MyDateInput(attrs={ 'min': (datetime.now()- timedelta(days=100*365)).strftime("%Y-%m-%d"), 'max': datetime.now().strftime("%Y-%m-%d"), 'class': 'required' ,'placeholder': 'YYYY-MM-DD', 'required': 'no'}))
我使用此代码在他们失败时向我发送电子邮件:
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super(RegistrationForm, self).__init__(*args, **kwargs)
def clean(self):
if self._errors and 'birthday' in self._errors and len(self._errors)==1:
mail_admins("BAD Birthday register",str(self._errors) + '\n' + str(self.request))
这是我收到的电子邮件的示例:
<ul class="errorlist"><li>birthday<ul class="errorlist"><li>Introduzca una fecha válida.</li></ul></li></ul>
<WSGIRequest
path:/community/register/,
GET:<QueryDict: {u'bundle_id': [u'com.test.test'], u'ver': [u'2.4']}>,
POST:<QueryDict: {u'first_name': [u'Mol'], u'last_name': [u'Mol'], u'gender': [u'f'], u'user_type': [u'3'], u'birthday': [u'2015-02-22'], u'csrfmiddlewaretoken': [u'fmx6QGTTkE2SbBzxlsKOwfPjjb4ztvjk'], u'password': [u'*******'], u'email': [u'some@email.com']}>,
META:{'CONTENT_LENGTH': '175',
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
'CSRF_COOKIE': 'fmx6QGTTkE2SbBzxlsKOwfPjjb4ztvjk',
'DOCUMENT_ROOT': '/usr/local/apache2/htdocs',
'GATEWAY_INTERFACE': 'CGI/1.1',
'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
'HTTP_ACCEPT_LANGUAGE': 'es-es',
'HTTP_CONNECTION': 'close',
'HTTP_COOKIE': 'csrftoken=fmx6QGTTkE2SbBzxlsKOwfPjjb4ztvjk; NREUM=h=1424188941317&r=281636&p=281636; __utma=175034791.2027745757.1424184041.1424184041.1424188639.2; __utmb=175034791.7.10.1424188639; __utmc=175034791; __utmt=1; __utmz=175034791.1424184041.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)',
'HTTP_FORWARDED_REQUEST_URI': '/community/register/?ver=2.4',
'HTTP_HOST': 'www.test.it',
'HTTP_HTTPS': 'on',
'HTTP_HTTP_X_FORWARDED_PROTO': 'https',
'HTTP_ORIGIN': 'https://www.test.it',
'HTTP_REFERER': 'https://www.test.it/community/register/? ver=2.4&bundle_id=com.27dv.tinytap',
'HTTP_USER_AGENT': 'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11A465',
具有类似格式的日期的其他请求已成功, 如果我用邮递员伪造这样的请求,它就会通过。
修改 这似乎只在
发生时才会发生'HTTP_ACCEPT_LANGUAGE': 'es-es',