回复: Stuck on "ViewDoesNotExist" last step of tutorial part 4
there's no function in views.py, you should define that 'index' handler
在 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.pyfrom django.conf.urls import patterns, include, urlfrom django.views.generic import DetailView, ListViewfrom polls.models import PollUncomment the next two lines to enable the admin:from django.contrib import adminadmin.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_404from django.http import HttpResponseRedirect, HttpResponsefrom django.core.urlresolvers import reversefrom django.template import RequestContextfrom polls.models import Choice, Polldef 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 += 1selected_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.To unsubscribe from this group, send email to django-users+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home