sultan sultan - 12 days ago 5
Python Question

Django class based generic views: cannot import name TemplateView

Django fires exception

cannot import name TemplateView
how to fix this?

view.py :

from django.views.generic import TemplateView

class Monitor(TemplateView):
template_name = 'helo.html'




urls.py :

from monitor.views import Monitor

urlpatterns = patterns('',
(r'^admin/', Monitor.as_view()),
)

Answer

I don't know what Django version you are using, but only in Django 1.3 a class called TemplateView exists. Its import should be:

from django.views.generic.base import TemplateView