[Django]-Django, name 'IndexView' is not defined

6👍

You have to create that IndexView and import it in your urls.py.
Currently the interpreter complains since in the urls.py IndexView is unknown.
To create a new view you should create a new class in views.py, something like:

from django.views.generic.base import TemplateView

class IndexView(TemplateView):
    template_name = 'index.html'

ps: please read the official Django docs, which is very good!

2👍

The IndexView class is in the boilerplate project’s views file.

C:\…\thinkster-django-angular-boilerplate-release\thinkster_django_angular_boilerplate\views

Copy and paste that content into your project’s views file.

from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic.base import TemplateView
from django.utils.decorators import method_decorator

class IndexView(TemplateView):
    template_name = 'index.html'

    @method_decorator(ensure_csrf_cookie)
    def dispatch(self, *args, **kwargs):
        return super(IndexView, self).dispatch(*args, **kwargs)

1👍

in your urls.py

from .views import IndexView
url('^.*$', IndexView.as_view(), name='index'),

(.views or yourProject.views)

in your views.py
do what daveoncode wrote

👤Sativa

Leave a comment