In Django I have form that is using the SplitDateTimeField which is set to have an initial value as shown below. When try view the template containing the form I get ValueError: “strftime format ends with raw %.”
# forms.py
class DiscountForm(Form):
title = CharField(widget=TextInput(), required=True)
description = CharField(widget=Textarea(), required=True)
fineprint = CharField(widget=Textarea(), required=True)
start = SplitDateTimeField(
input_date_formats='%m/%d/%Y',
input_time_formats='%I:%M %p',
initial= lambda: dt.datetime.now(),
required=True
)
end = SplitDateTimeField(
input_date_formats='%m/%d/%Y',
input_time_formats='%I:%M %p',
initial= lambda: dt.datetime.now() + dt.timedelta(days=30),
required=True
)
limit = IntegerField(min_value=0, initial=0, required=True)
# relevant in settings.py
USE_I18N = False
USE_L10N = False
USE_TZ = True
DATETIME_INPUT_FORMATS = ('%m/%d/%Y %I:%M %p')
DATE_INPUT_FORMATS = ('%m/%d/%Y')
TIME_INPUT_FORMATS = ('%I:%M %p')
Here is my traceback: http://dpaste.org/y55eV/
Any guidance is greatly appreciated. Thank you
The arguments
input_date_formatsandinput_time_formatsneed to be lists or tuples, not strings (see SplitDateTimeField in documentation). The error may be caused that it is now iterating over characters instead of multiple input formats.Try changing the code to the following: