0

我在 ./manage.py shell 中输入的以下代码

import datetime
from django.db import models
class ContactForm(forms.Form):
... date = DateField(widget=CalendarWidget)
... name = CharField(max_length=40, widget=OtherWidget)
...
Traceback (最近的电话last):
File "", line 1, in
File "", line 2, in ContactForm
NameError: name 'DateField' is not defined

如果还有什么要导入的。如果是这样,请告诉我,并提前感谢...

4

2 回答 2

2
class ContactForm(forms.Form):
    date = forms.DateField(widget=CalendarWidget)
    name = forms.CharField(max_length=40, widget=OtherWidget)
于 2013-03-15T10:08:12.203 回答
1

您应该导入django.forms

from django import forms

class ContactForm(forms.Form):
    date = forms.DateField(widget=CalendarWidget)
    name = forms.CharField(max_length=40, widget=OtherWidget)

编辑:或者让你的代码工作,你可以这样做:

from django import forms
from django.forms.fields import *

class ContactForm(forms.Form):
    date = DateField(widget=CalendarWidget)
    name = CharField(max_length=40, widget=OtherWidget)
于 2013-03-15T10:10:41.117 回答