我在 Django-python 中有一个用于事件程序的表单。我正在尝试使用icalendar为事件创建一个ics文件,为此,我想从表单中的变量“starttime”和“endtime”获取值“dtstart”和“dtend”,但我得到了代码:日期时间格式错误。有人有解决这个问题的建议吗?
错误
elif not ical[15:]:
return datetime(*timetuple)
elif ical[15:16] == 'Z':
return pytz.utc.localize(datetime(*timetuple))
else:
raise ValueError(ical)
except:
raise ValueError('Wrong datetime format: %s' % ical) …
class vDuration(object):
"""Subclass of timedelta that renders itself in the iCalendar DURATION
format.
"""
代码
def event(request, id=None):
instance = Event_cal()
if id:
instance = get_object_or_404(Event_cal, pk=id)
else:
instance = Event_cal()
form = EventForm(request.POST or None, instance=instance)
if request.POST and form.is_valid():
form.save()
startdate = request.POST.get('starttime')
endate = request.POST.get('endtime')
event = Event()
event.add('summary', 'My Summary')
event.add('dtstart', vDatetime.from_ical(startdate))
event.add('dtend', vDatetime.from_ical(endate))
先谢谢了,我正在学习python,所以我没有太多经验。
慕哥6287543
相关分类