Django new user: NameError even though class is defined in views -
i new python , newer django. following effectivedjango tutorial . project folder has following structure.
addressbook - addressbook - _init_.py - settings.py - urls.py - wsgi.py - _init_.pyc - settings.pyc - urls.pyc - wsgi.pyc - contacts - forms.py - _init_.py - models.py - tests.py - views.py - forms.pyc - _init_.pyc - models.pyc - tests.pyc - views.pyc - templates - contact_list.html - edit_contact.html</li>
views:
# create views here. django.views.generic import listview django.core.urlresolvers import reverse django.views.generic import createview contacts.models import contact import forms class listcontactview(listview): model = contact template_name = 'contact_list.html' class createcontactview(createview): model = contact template_name = 'edit_contact.html' form_class = forms.contactform def get_success_url(self): return reverse('contacts-list') class updatecontactview(updateview): model = contact template_name = 'edit_contact.html' form_class = forms.contactform
models:
from django.db import models # create models here. class contact(models.model): first_name = models.charfield( max_length=255, ) last_name = models.charfield( max_length=255, ) email = models.emailfield() def __str__(self): return ' '.join([ self.first_name, self.last_name, ])
urls
from django.conf.urls import patterns, include, url # uncomment next 2 lines enable admin: # django.contrib import admin # admin.autodiscover() import contacts.views urlpatterns = patterns('',url(r'^$', contacts.views.listcontactview.as_view(), name='contacts-list',), url(r'^new$', contacts.views.createcontactview.as_view(), name='contacts-new',), # examples: # url(r'^$', 'addressbook.views.home', name='home'), # url(r'^addressbook/', include('addressbook.foo.urls')), # uncomment admin/doc line below enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # uncomment next line enable admin: # url(r'^admin/', include(admin.site.urls)), )
when try run development server through virtualenv following errors:
traceback: ... file "/home/rudresh/tutorial/addressbook/addressbook/urls.py" in <module> 7. import contacts.views file "/home/rudresh/tutorial/addressbook/contacts/views.py" in <module> 23. class updatecontactview(updateview): exception type: nameerror @ /new exception value: name 'updateview' not defined
i thought defined updateview in views dont know doing wrong. suggestion appreciated.
thanks
in views, use listview
, createview
, updateview
, import listview
, createview
.
views.py:
from django.views.generic import listview, createview, updateview django.core.urlresolvers import reverse contacts.models import contact import forms ...
Comments
Post a Comment