python - no module named HelloTemplate Import Error -


i getting import error. says there no module named hellotemplate. there hellotemplate class have imported in urls.py file. "login" django app name.

this views.py file.

#from django.shortcuts import render django.http import  httpresponse django.template.loader import get_template django.template import context django.shortcuts import render_to_response django.views.generic.base import templateview # create views here. def hello(request):     name='zeeshan'     html="<html><body> hi %s.</body></html>" %name     return httpresponse(html)  def hello_template(request):     name='zeeshan'     t=get_template('hello.html')     html=t.render(context({'name':name}))     return httpresponse(html)  class hellotemplate (templateview):         template_name="hello_class.html"          def get_context_data(self,  **kwargs):             context=super(hellotemplate,  self).get_context_data(**kwargs)             context["name"] = "zee"             return context 

this url.py file..

from django.conf.urls import include, url django.contrib import admin login.views import hellotemplate  urlpatterns = [     #url(r'^admin/', include(admin.site.urls)),     url(r'^hello/$', 'login.views.hello'),      url(r'^hello_template/$', 'login.views.hello_template'),      url(r'^hello_class_view/$','hellotemplate.as_view()'),  ] 

here error report while running on local server.

importerror @ /hello_class_view/  no module named hellotemplate  request method:     request url:    http://127.0.0.1:8000/hello_class_view/ django version:     1.8.4 exception type:     importerror exception value:      no module named hellotemplate  exception location:     /usr/lib/python2.7/importlib/__init__.py in        import_module, line 37 python executable:  /home/grayhat/documents/python/projects/bin/python python version:     2.7.6 python path:      ['/home/grayhat/documents/python/projects/myapp',  '/home/grayhat/documents/python/projects/local/lib/python2.7/site-packages/django-1.8.4-py2.7.egg',  '/home/grayhat/documents/python/projects/lib/python2.7/site-packages/django-1.8.4-py2.7.egg',  '/home/grayhat/documents/python/projects/lib/python2.7',  '/home/grayhat/documents/python/projects/lib/python2.7/plat-x86_64-linux-gnu',  '/home/grayhat/documents/python/projects/lib/python2.7/lib-tk',  '/home/grayhat/documents/python/projects/lib/python2.7/lib-old',  '/home/grayhat/documents/python/projects/lib/python2.7/lib-dynload',  '/usr/lib/python2.7',  '/usr/lib/python2.7/plat-x86_64-linux-gnu',  '/usr/lib/python2.7/lib-tk',  '/home/grayhat/documents/python/projects/local/lib/python2.7/site-packages',  '/home/grayhat/documents/python/projects/lib/python2.7/site-packages']  server time:    mon, 21 sep 2015 08:06:38 +0000 

the snippet in urls.py 'hellotemplate.as_view()' should hellotemplate.as_view(). is, without quotes. can see more on referencing class based views here.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -