index.html を作成し、TemplateView を使用します。インデックスにアクセスしようとすると、インデックス ビューが定義されていないというエラーが表示されました。理由はわかりません。このパターンに従っているだけです https://docs.djangoproject.com/en/dev/topics/class-based-views/#subclassing-generic-views
ここに私のコードがあります:
urls.py
from django.conf.urls import patterns, url
from . import views
urlpatterns = patterns('',
url(
r'^$',
views.IndexView.as_view(),
name='index'
),
)
ビュー.py
from django.views.generic import TemplateView
def IndexView(TemplateView):
template_name = 'index.html'
トレースバック (更新)
Environment:
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.5
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'accounts',
'front')
Installed 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" in get_response
103. resolver_match = resolver.resolve(request.path_info)
File "/home/cath/virtualenvs/autovine_env/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
319. for pattern in self.url_patterns:
File "/home/cath/virtualenvs/autovine_env/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in 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" in urlconf_module
342. self._urlconf_module = import_module(self.urlconf_name)
File "/home/cath/virtualenvs/autovine_env/local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/cath/src/autovine/autovine/urls.py" in <module>
33. include('front.urls', namespace="front")
File "/home/cath/virtualenvs/autovine_env/local/lib/python2.7/site-packages/django/conf/urls/__init__.py" in include
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
35. __import__(name)
File "/home/cath/src/autovine/autovine/apps/front/urls.py" in <module>
8. IndexView.as_view(),
Exception Type: NameError at /
Exception Value: name 'IndexView' is not defined