user2235971
user2235971

Reputation: 33

Getting Error while going through with django doc

The following code I'm Typing in ./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 (most recent call last):
File "", line 1, in
File "", line 2, in ContactForm
NameError: name 'DateField' is not defined

If there anything else to import. If so, please tell me about that and thanks in advance...

Upvotes: 0

Views: 122

Answers (2)

dmg
dmg

Reputation: 7716

You should import django.forms:

from django import forms

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

EDIT: Or to make your code work you can do:

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

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

Upvotes: 1

catherine
catherine

Reputation: 22808

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

Upvotes: 2

Related Questions