django TypeError期望的字符串或缓冲区

时间:2014-11-11 06:03:45

标签: django date

我有一个观点:

def TakeAppointmentView(request):
    appointment_date = request.GET.get('appointment_date',False)
    app = Appointment()
    app.appointment_date = appointment_date
    app.save()

我有预约模特。当我这样做时,它会给出错误说“预期字符串或缓冲区”,但日期将保存在数据库中。保存在数据库中工作正常,但会出错。

这有什么不对吗??

class AppointmentForm(forms.Form):
    appointment_date = forms.DateField()

    def clean_appointment_date(self):
        appointment_date = self.cleaned_data['appointment_date']
        today = date.today()
        next_week = today + timedelta(days=7)
        if appointment_date is None:
            raise forms.ValidationError("You must provide a date to take appointment")
        if appointment_date < today:
            raise forms.ValidationError("You cannot take appointment on past date")
        if appointment_date > next_week:
            raise forms.ValidationError("You can only take appointment with in one week")
    return appointment_date

此外,表单未经过验证..如果与验证不匹配,则不显示任何错误消息..

它踢我的屁股......

任何帮助??

0 个答案:

没有答案