Django 教程,Getting: TypeError at /admin/ argument to reversed() must be a sequence

Django tutorial, Getting: TypeError at /admin/ argument to reversed() must be a sequence

我正在学习 1.8 版的 django 教程,但遇到一个错误,我一直卡在上面,似乎无法弄清楚。我以为我几乎是在按照 T 的教程进行操作。

我设置了以下树:

. ├── dj_project │   ├── __init__.py │   ├── __init__.pyc │   ├── settings.py │   ├── settings.pyc │   ├── urls.py │   ├── urls.pyc │   ├── wsgi.py │   └── wsgi.pyc ├── manage.py └── polls ├── admin.py ├── admin.pyc ├── __init__.py ├── __init__.pyc ├── migrations │   ├── 0001_initial.py │   ├── 0001_initial.pyc │   ├── __init__.py │   └── __init__.pyc ├── models.py ├── models.pyc ├── tests.py ├── urls.py ├── urls.pyc ├── views.py └── views.pyc

并且有,就像在 polls/urls.py:

的教程中一样
from django.conf.urls import url

from . import views

urlpatterns = {
    url(r'^$', views.index, name='index'),
}

对于我的 dj_project/urls.py

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [

    url(r'^polls/', include('polls.urls')), 
    url(r'^admin/', include(admin.site.urls)),

]

polls/views.py中我有:

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
    return HttpResponse("is there something here?")

所以当我转到 <mysite>/polls 时,我看到 "is there something here",但是如果我转到 <mysite>/admin,我得到错误:TypeError at /admin/ argument to reversed() must be a sequence。如果我从 dj_project/urls.py 中的 urlpatterns 中删除民意调查,管理员就可以了。

可能是什么问题?我似乎无法弄清楚。

polls/urls.py文件中, 您将 urlpatterns 声明为字典,它必须是一个列表。

改变

urlpatterns = {
    url(r'^$', views.index, name='index'),
}

至:

urlpatterns = [
    url(r'^$', views.index, name='index'),
]