Django 1.5 - Cannot find the defined view when using TemplateView -
I am creating index.html and I use TemplateView. When I'm trying to use my index, I get an error that my index view is not defined. I do not know why, I follow this method
These are my codes:
urls.py views.py from Template: Strong> (updated) You are getting an error because you have not imported the is accessible within, you should rewrite your import details - Or rewrite your urlconf - It may be that Python's name is read in place - this is what your On that, you have defined your view as a function rather than that class -
Import pattern from Django.conf.urls, import view urlpatterns = pattern ('', url (r '^ $', views.IndexView.as_view (), name = 'index') from url) <
Environment: Request method: Request URL: http: // localhost: 8000 / Django Version: 1.5 Python Version: 2.7. 3 installed Application: ('django .contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles' "Djangokcontrib Kadmin 'Djangokcontribkadmindocs' accounts',' set up ') Middleware: (' django.middleware.common.CommonMiddleware ',' django.contrib.sessions.middleware.SessionMiddleware ' , 'django.middleware .csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware') traceback file "/ home / cath / Virtualenvs / Autovine_env / local / lib / python2.7 / site-packages / Django / core / handlers / base.py "103. in get_response resolver_match = resolver.resolve (request.path_info) file" / home / cath / virtualenvs / autovine_env / local / lib / python2 .7 / Site-packages / django / core / urlresolvers.py "in the self.url_patterns, in the format 319. For:" file / home / cath / virtualenvs / autovine_env / local / lib /python2.7/site-packages/django/core /urlresolvers.py "url_patterns 347 patterns = getattr (self.urlconf_module," urlpatterns ", self.urlconf_module) file" / home / cath / Virtualenvs / Autovine_env / local / lib / python2.7 / site-packages / Django / core / urlresolvers.py "urlconf_module 342. self._urlconf_module in = import_module (self.urlconf_name) file" /home/cath/virtualenvs/autovine_env/local/lib/python2.7 /site-packages/django/utils/importlib.py " Import_module 35. __import__ (name) in the file "/home/cath/src/autovine/autovine/urls.py" & lt; Module & gt; 33. Include ('front.urls', name space = "front") file "/home/cath/virtualenvs/autovine_env/local/lib/python2.7/site-packages/django/conf/urls/__init__.py "25. urlconf_module = import_module (urlconf_module) file" /home/cath/virtualenvs/autovine_env/local/lib/python2.7/site-packages/django/utils/importlib.py in import_module in "35. __import __ (name) Includes the file "/home/cath/src/autovine/autovine/apps/front/urls.py" in & lt; Module & gt; 8. IndexView.as_view (), exception type: error / exception value on name: name 'indexview' is not defined
IndexView in the current namespace, you have imported
view
IndexView Only
views namespace - i.e.
views.indexview .
see yourapp.views import index
urlpatterns = pattern ('', url (r '^ $', views.IndexView.as_view (), name = 'index'),)
NameError is the exception.
class indexview (TemplateView):
instead of
Def Definitive View (TemplateView):
Comments
Post a Comment