Django DateTimeField无法验证ISO 8601格式
forms.py
from django import forms
class ImageForm(forms.Form):
updatedAfter = forms.DateTimeField()
createdAfter = forms.DateTimeField()
views.py
class ImageView(View)
def get_form(self):
return ImageForm(data=self.request.GET or None)
def get(self, request, *args, **kwargs):
form = self.get_form()
if form.is_valid():
...
这是我的要求:
http://127.0.0.1:8001/images/?updatedAfter=2011-10-05T14:48:00.000Z&createdAfter=2011-10-05T14:48:00.000Z
答案 0 :(得分:2)
尝试编辑以下设置,它对我有用:
<强> settings.py 强>
USE_L10N = False
DATETIME_INPUT_FORMATS = ('%Y-%m-%dT%H:%M:%S.%fZ',)