there's no function in views.py, you should define that 'index' handler -- Sincerely, Pengfei Xue
已使用 Sparrow (http://www.sparrowmailapp.com/?sig) 已使用 Sparrow (http://www.sparrowmailapp.com/?sig) 在 2012年8月15日星期三,上午11:16,Sky 写道: > I've having a similar problem here using Django 1.4 and I can't quite figure > what's wrong. The error reads: Could not import polls.views.index. View does > not exist in module polls.views. > > urls.py > > from django.conf.urls import patterns, include, url > from django.views.generic import DetailView, ListView > from polls.models import Poll > > Uncomment the next two lines to enable the admin: > from django.contrib import admin > admin.autodiscover() > > urlpatterns = patterns('', > url(r'^$', > ListView.as_view( > queryset = Poll.objects.order_by('-pub_date')[:5], > context_object_name = 'latest_poll_list', > template_name = 'polls/index.html')), > url(r'^(?P<pk>\d+)/$', > DetailView.as_view( > model = Poll, > template_name = 'polls/detail.html')), > url(r'^(?P<pk>\d+)/results/$', > DetailView.as_view( > model = Poll, > template_name = 'polls/results.html'), > name='poll_results'), > url(r'^(?P<poll_id>\d+)/vote/$', 'polls.views.vote'), > ) > > urlpatterns = patterns('', > url(r'^polls/', include('polls.urls')), > url(r'^admin/', include(admin.site.urls)), > ) > > # Uncomment the admin/doc line below to enable admin documentation: > # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), > > views.py > # Create your views here. > from django.shortcuts import render_to_response, get_object_or_404 > from django.http import HttpResponseRedirect, HttpResponse > from django.core.urlresolvers import reverse > from django.template import RequestContext > from polls.models import Choice, Poll > > def vote(request, poll_id): > p = get_object_or_404 (Poll, pk = poll_id) > try: > selected_choice = p.choice_set.get(pk=request.POST['choice']) > except (KeyError, Choice.DoesNotExist): > return render_to_response('polls/detail.html', { > 'poll': p, > 'error_message': "You didn't select a choice.", > }, context_instance = RequestContext(request)) > else: > selected_choice.votes += 1 > selected_choice.save() > return HttpResponseRedirect(reverse('poll_results', args = (p.id,))) > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/bWqxut6y_YgJ. > To post to this group, send email to django-users@googlegroups.com > (mailto:django-users@googlegroups.com). > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > (mailto:django-users+unsubscr...@googlegroups.com). > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.