我正在跟随一个Django教程,突然当我尝试访问http://127.0.0.1:8000/admin/时,它给了我一个TemplateSyntaxError。
TemplateSyntaxError at /admin/
在渲染时捕获ViewDoesNotExist:尝试在模块polls.views中查找results。错误是:'module'对象没有属性'results'
它突出显示了这一行: {% url 'django-admindocs-docroot' as docsroot %}
管理员页面在我进行教程的第3部分之前完美地工作,但我更改了URL,尽管我按照他们说的方式做了,所以我怀疑这不是问题。 urls.py:
TemplateSyntaxError at /admin/
在渲染时捕获ViewDoesNotExist:尝试在模块polls.views中查找results。错误是:'module'对象没有属性'results'
它突出显示了这一行: {% url 'django-admindocs-docroot' as docsroot %}
管理员页面在我进行教程的第3部分之前完美地工作,但我更改了URL,尽管我按照他们说的方式做了,所以我怀疑这不是问题。 urls.py:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^polls/$', 'polls.views.index'),
(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
(r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),
(r'^admin/', include(admin.site.urls)),
)
admin.py:
from polls.models import Poll
from polls.models import Choice
from django.contrib import admin
class ChoiceInline(admin.TabularInline):
model = Choice
extra = 0
class PollAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['question']}),
('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
]
inlines = [ChoiceInline]
list_display = ('question', 'pub_date')
list_filter = ['pub_date']
search_fields = ['question']
date_hierarchy = 'pub_date'
admin.site.register(Poll, PollAdmin)
views.py:
from django.http import HttpResponse
from polls.models import Poll
from django.template import Context, loader
def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
t = loader.get_template('polls/index.html')
c = Context({
'latest_poll_list': latest_poll_list,
})
return HttpResponse(t.render(c))
def detail(request, poll_id):
return HttpResponse("You're looking at poll %s. " % poll_id)
def vote(request, poll_id):
return HttpResponse("You're voting on poll %s." % poll_id)