Django DateTimeField无法验证ISO 8601格式

时间:2018-02-09 15:43:30

标签: python django

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

1 个答案:

答案 0 :(得分:2)

尝试编辑以下设置,它对我有用:

<强> settings.py

USE_L10N = False

DATETIME_INPUT_FORMATS = ('%Y-%m-%dT%H:%M:%S.%fZ',)