tutorial part 4: ImportError

368 views
Skip to first unread message

steph

unread,
Nov 23, 2010, 11:06:06 AM11/23/10
to Django users
Hi group,

I'm new - just worked thgough the tutorial. In part 4 about the use of
generic views I've got a problem - I can't import ListView and
DetailView:

>>> from django.views.generic import DetailView
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name DetailView
>>> from django.views.generic import ListView
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name ListView

I'm on the newest version of django: first tried with version 1.2.3,
then I upgraded to 1.3 alpha - same problem.

Any clues?

thanks,
stephan

ps: other than that it's a great tutorial!

Michael Sprayberry

unread,
Nov 23, 2010, 11:37:42 AM11/23/10
to django...@googlegroups.com
Steph,
 
those instructions are incorrect try
from djanog.views.generic import list_view, list_detail
 
Michael

--- On Tue, 11/23/10, steph <step...@yahoo.de> wrote:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


Robbington

unread,
Nov 23, 2010, 11:42:09 AM11/23/10
to Django users
Firstly friend,

1.3 alpha has been released as a testing package. It isnt the most
stable version and not meant for production, I would revert back to
1.2 unless your plan is to help the django team with bug fixes.


Also, you are reading the wrong tutorial for your version, that is
why you are getting that error.

http://docs.djangoproject.com/en/1.2/intro/tutorial04/

Here is the one you want, I can see why that would be a bit confusing
to you.

Rob

Daniel Roseman

unread,
Nov 23, 2010, 11:44:22 AM11/23/10
to Django users
Are you sure you've upgraded correctly? It won't work at all if you
have anything less than 1.3 alpha - the tutorial you're using is for
the development version only (there's a big link at the top of the
page for the one that works in previous versions), and generic views
are one big element that has changed since 1.2. How did you install
1.3?
--
DR.

steph

unread,
Nov 25, 2010, 4:06:44 AM11/25/10
to Django users
>>> import django.views.generic
>>> dir (django.views.generic)
['GenericViewError', '__builtins__', '__doc__', '__file__',
'__name__', '__package__', '__path__', 'list_detail']

ok, I can see list_detail now :-) ... but the other?

maybe a problem with my installation ...

On 23 Nov., 17:37, Michael Sprayberry <michaelspraybe...@yahoo.com>
wrote:
> Steph,
>  
> those instructions are incorrect try
> from djanog.views.generic import list_view, list_detail
>  
> Michael
>
> --- On Tue, 11/23/10, steph <stepha...@yahoo.de> wrote:
>
> From: steph <stepha...@yahoo.de>
> Subject: tutorial part 4: ImportError
> To: "Django users" <django...@googlegroups.com>
> Date: Tuesday, November 23, 2010, 11:06 AM
>
> Hi group,
>
> I'm new - just worked thgough the tutorial. In part 4 about the use of
> generic views I've got a problem - I can't import ListView and
> DetailView:
>
> >>> from django.views.generic import DetailView
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ImportError: cannot import name DetailView>>> from django.views.generic import ListView
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ImportError: cannot import name ListView
>
> I'm on the newest version of django: first tried with version 1.2.3,
> then I upgraded to 1.3 alpha - same problem.
>
> Any clues?
>
> thanks,
> stephan
>
> ps: other than that it's a great tutorial!
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.

steph

unread,
Nov 25, 2010, 4:11:23 AM11/25/10
to Django users
Ok, sorry - didn't get it about the tutorial versions ... it didn't
appear to me that 1.2 tutorial was about version 1.2.3. - silly me ;-)

How I did install 1.3: download ... setup.py. Just as in INSALL-file.

Robbington

unread,
Nov 25, 2010, 4:18:03 AM11/25/10
to Django users
As mentioned before,

If you are using Django 1.2 you dont need to import list_view or
detail_view just 'from django.conf.urls.defaults import *'

As the tutorial documentation for 1.2 http://docs.djangoproject.com/en/1.2/intro/tutorial04/
instructs:

from django.conf.urls.defaults import *
from polls.models import Poll

info_dict = {
'queryset': Poll.objects.all(),
}

urlpatterns = patterns('',
(r'^$', 'django.views.generic.list_detail.object_list',
info_dict),
(r'^(?P<object_id>\d+)/$',
'django.views.generic.list_detail.object_detail', info_dict),
url(r'^(?P<object_id>\d+)/results/$',
'django.views.generic.list_detail.object_detail', dict(info_dict,
template_name='polls/results.html'), 'poll_results'),
(r'^(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
)

Rob
Message has been deleted
Message has been deleted

screened

unread,
Jan 31, 2011, 3:54:49 PM1/31/11
to django...@googlegroups.com
Hi group,

I've noticed a few things in the tutorial documentation for 1.2 on page http://docs.djangoproject.com/en/1.2/intro/tutorial04/ under the section "Use generic views: Less code is better":

1.  It instructs the user to rename both the detail.html and list.html pages to poll_*.html, but it doesn't say to rename the results.html file to poll_results.html, which in turn in polls/urls.py, the template_name='polls/results.html' seems to need to be changed to template_name='polls/poll_results.html' to be properly used by the generic views. 

2. Also, in polls/views.py, in the vote model, poll_id needs to be changed to object_id in the signature, although the instructions only say to change these references in the templates and in the render_to_response call (it may have been implied to change the vote model signature when the author says that 'The object_detail() generic view expects the ID value captured from the URL to be called "object_id", so we've changed poll_id to object_id for the generic views.', - if this is the case then ignore this one :) 

3. Also in polls/urls.py in the import line "from django.conf.urls.defaults import *" seems to be an unused import

Can someone check to make sure that I am correct on this list?  Maybe I am off-base on some of this.  Thank you!

screened

unread,
Jan 31, 2011, 4:19:24 PM1/31/11
to django...@googlegroups.com
**some corrections from my previous post
By "model" I mean "view" and in #1, index.html gets changed to poll_list.html
Sorry!
Reply all
Reply to author
Forward
0 new messages