problem with using generic views

638 views
Skip to first unread message

Doaa Hassan

unread,
Aug 8, 2015, 9:32:25 AM8/8/15
to Django users
Hi all,

I am trying to convert poll app introduced on:

https://docs.djangoproject.com/en/1.8/intro/tutorial01/

 to use the generic views system as described on:

https://docs.djangoproject.com/en/1.8/intro/tutorial04/

 However, when I  convert the URLconf  by opening  the polls/urls.py and change it like so:

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
    url(r'^(?P<pk>[0-9]+)/results/$', views.ResultsView.as_view(), name='results'),
    url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
]

then reload the polls app (http://localhost:8000/polls/), I got the following error:


'module' object has no attribute 'IndexView'


Traceback:

File "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\handlers\base.py" in get_response
119. resolver_match = resolver.resolve(request.path_info)
File "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py" in resolve
366. for pattern in self.url_patterns:
File "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py" in url_patterns
402. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py" in urlconf_module
396. self._urlconf_module = import_module(self.urlconf_name)
File "C:\Python27\Lib\importlib\__init__.py" in import_module
37. __import__(name)
File "C:\Users\nti\Desktop\test_env\myapp\myapp\urls.py" in <module>
21. url(r'^polls/', include('polls.urls', namespace="polls")),
File "C:\Users\nti\Desktop\test_env\lib\site-packages\django\conf\urls\__init__.py" in include
33. urlconf_module = import_module(urlconf_module)
File "C:\Python27\Lib\importlib\__init__.py" in import_module
37. __import__(name)
File "C:\Users\nti\Desktop\test_env\myapp\polls\urls.py" in <module>
25. url(r'^$', views.IndexView.as_view(), name='index'),

Exception Type: AttributeError at /polls/
Exception Value: 'module' object has no attribute 'IndexView'

--------------------------------
Do you have any clue to fix the problem? 

Thanks.

Best regards,
Doaa

James Schneider

unread,
Aug 8, 2015, 4:42:57 PM8/8/15
to django...@googlegroups.com

Did you complete the following section after changing the urls.conf? The URL changes won't work until you modify the views.py file in the next section.

https://docs.djangoproject.com/en/1.8/intro/tutorial04/#amend-views

-James

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6f61448d-d30c-4d22-a198-75e33ceeefac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Doaa Hassan

unread,
Aug 10, 2015, 10:43:59 AM8/10/15
to Django users
 No, I didn't, but I just have done and it works. Thanks :)
Reply all
Reply to author
Forward
0 new messages